library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(ggplot2)
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.0 ──
## ✔ tibble  3.0.6     ✔ purrr   0.3.4
## ✔ tidyr   1.1.2     ✔ stringr 1.4.0
## ✔ readr   1.4.0     ✔ forcats 0.5.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
library(GGally)
## Registered S3 method overwritten by 'GGally':
##   method from   
##   +.gg   ggplot2
library(tswge)
## 
## Attaching package: 'tswge'
## The following object is masked from 'package:datasets':
## 
##     uspop
library(nnfor)
## Loading required package: generics
## 
## Attaching package: 'generics'
## The following object is masked from 'package:dplyr':
## 
##     explain
## The following objects are masked from 'package:base':
## 
##     as.difftime, as.factor, as.ordered, intersect, is.element, setdiff,
##     setequal, union
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
library(forecast)
library(vars)
## Loading required package: MASS
## 
## Attaching package: 'MASS'
## The following object is masked from 'package:tswge':
## 
##     cement
## The following object is masked from 'package:dplyr':
## 
##     select
## Loading required package: strucchange
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## Loading required package: sandwich
## 
## Attaching package: 'sandwich'
## The following object is masked from 'package:generics':
## 
##     estfun
## 
## Attaching package: 'strucchange'
## The following object is masked from 'package:stringr':
## 
##     boundary
## Loading required package: urca
## Loading required package: lmtest
## 
## Attaching package: 'lmtest'
## The following object is masked from 'package:tswge':
## 
##     wages
library(tswge)

library(tidyverse)
library(GGally)
library(astsa)
## 
## Attaching package: 'astsa'
## The following object is masked from 'package:forecast':
## 
##     gas
## The following object is masked from 'package:tswge':
## 
##     flu
library(dygraphs)
READING IN THE DATA
goldoriginal = read.csv("/Users/hallepurdom/Desktop/GoldUP.csv", header=TRUE)

#gold=data.frame(goldoriginal$Date,goldoriginal$Gold_Price,goldoriginal$Crude_Oil,goldoriginal$Interest_Rate,goldoriginal$USD_Index,gold$CPI)

gold=dplyr::select(goldoriginal,-Sensex,-USD_INR)

ggpairs(gold[2:6])

plotts.wge(gold$Gold_Price)

plotts.wge(gold$Crude_Oil)

plotts.wge(gold$Interest_Rate)

plotts.wge(gold$CPI)

acf(gold$Gold_Price[1:119], plot=TRUE)

acf(gold$Gold_Price[119:239], plot=TRUE)

UNIVARIATE ARIMA MODELING
# Looking at gold prediction realization
aic5.wge(gold$Gold_Price, type = 'aic', p=0:15, q=0:5)
## ---------WORKING... PLEASE WAIT... 
## 
## 
## Error in aic calculation at 1 0 
## Error in aic calculation at 1 1 
## Error in aic calculation at 1 2 
## Error in aic calculation at 1 3 
## Error in aic calculation at 1 4 
## Error in aic calculation at 1 5 
## Error in aic calculation at 2 0 
## Error in aic calculation at 2 1 
## Error in aic calculation at 2 2 
## Error in aic calculation at 2 3 
## Error in aic calculation at 2 4 
## Error in aic calculation at 2 5 
## Error in aic calculation at 3 0 
## Error in aic calculation at 3 1 
## Error in aic calculation at 3 2 
## Error in aic calculation at 3 3 
## Error in aic calculation at 3 4 
## Error in aic calculation at 3 5 
## Error in aic calculation at 4 0 
## Error in aic calculation at 4 1 
## Error in aic calculation at 4 2 
## Error in aic calculation at 4 3 
## Error in aic calculation at 4 4 
## Error in aic calculation at 4 5 
## Error in aic calculation at 5 0 
## Error in aic calculation at 5 1 
## Error in aic calculation at 5 2 
## Error in aic calculation at 5 3 
## Error in aic calculation at 5 4 
## Error in aic calculation at 5 5 
## Error in aic calculation at 6 0 
## Error in aic calculation at 6 1 
## Error in aic calculation at 6 2 
## Error in aic calculation at 6 3 
## Error in aic calculation at 6 4 
## Error in aic calculation at 7 0 
## Error in aic calculation at 7 1 
## Error in aic calculation at 7 2 
## Error in aic calculation at 7 3 
## Error in aic calculation at 7 4 
## Error in aic calculation at 7 5 
## Error in aic calculation at 8 0 
## Error in aic calculation at 8 1 
## Error in aic calculation at 8 2 
## Error in aic calculation at 8 3 
## Error in aic calculation at 8 4 
## Error in aic calculation at 8 5 
## Error in aic calculation at 9 0 
## Error in aic calculation at 9 1 
## Error in aic calculation at 9 2 
## Error in aic calculation at 9 4 
## Error in aic calculation at 9 5 
## Error in aic calculation at 10 0 
## Error in aic calculation at 10 1 
## Error in aic calculation at 10 2 
## Error in aic calculation at 10 3 
## Error in aic calculation at 10 5 
## Error in aic calculation at 11 0 
## Error in aic calculation at 11 1 
## Error in aic calculation at 11 2 
## Error in aic calculation at 11 3 
## Error in aic calculation at 11 4 
## Error in aic calculation at 11 5 
## Error in aic calculation at 12 0 
## Error in aic calculation at 12 1 
## Error in aic calculation at 12 2 
## Error in aic calculation at 12 3 
## Error in aic calculation at 12 4 
## Error in aic calculation at 12 5 
## Error in aic calculation at 13 0 
## Error in aic calculation at 13 1 
## Error in aic calculation at 13 2 
## Error in aic calculation at 13 3 
## Error in aic calculation at 14 0 
## Error in aic calculation at 14 1 
## Error in aic calculation at 14 2 
## Error in aic calculation at 14 3 
## Error in aic calculation at 14 4 
## Error in aic calculation at 14 5 
## Error in aic calculation at 15 0 
## Error in aic calculation at 15 1 
## Error in aic calculation at 15 2 
## Error in aic calculation at 15 3 
## Error in aic calculation at 15 5 
## Five Smallest Values of  aic 
##     p    q        aic
##    10    4   13.23621
##     9    3   13.25121
##    13    4   13.26834
##    13    5   13.36857
##     0    5   14.85116
##ARMA modelling ARMA(10,4)
est_gold = est.arma.wge(gold$Gold_Price, p=10, q=4)
##   
##   
## Coefficients of AR polynomial:  
## 0.4112 0.5041 0.8741 -0.4070 -0.3572 0.0423 0.0393 -0.0873 0.0660 -0.0871 
## 
##                            AR Factor Table 
## Factor                 Roots                Abs Recip    System Freq 
## 1+1.0249B+0.9905B^2   -0.5174+-0.8613i      0.9952       0.3361
## 1-1.9687B+0.9690B^2    1.0159+-0.0052i      0.9844       8e-04
## 1+1.4197B+0.5960B^2   -1.1911+-0.5092i      0.7720       0.4357
## 1-0.9516B+0.4107B^2    1.1583+-1.0454i      0.6409       0.1169
## 1+0.0645B+0.3709B^2   -0.0869+-1.6398i      0.6090       0.2584
##   
##   
##   
##   
## Coefficients of MA polynomial:  
## -0.8295 -0.3089 0.6307 0.4705 
## 
##                               MA FACTOR TABLE 
## Factor                 Roots                Abs Recip    System Freq 
## 1+0.9823B+0.9528B^2   -0.5155+-0.8853i      0.9761       0.3339
## 1-0.7833B              1.2767               0.7833       0.0000
## 1+0.6305B             -1.5861               0.6305       0.5000
##   
## 
est_gold$phi
##  [1]  0.41121405  0.50410977  0.87411197 -0.40696447 -0.35723222  0.04229681
##  [7]  0.03929800 -0.08733518  0.06601412 -0.08713031
est_gold$theta
## [1] -0.8294786 -0.3088682  0.6307120  0.4705470
est_gold$avar
## [1] 494193.6
##using burg estimates to select phi and theta
##est_gold_burg = est.arma.wge(gold$Gold_Price,p=10, q=4,type='burg')
#fore_arma = fore.arma.wge(gold$Gold_Price, phi=est_gold$phi, theta = est_gold$theta, n.ahead=50, #lastn=TRUE, limits=TRUE)
##forecast ahead
fore_arma = fore.arma.wge(gold$Gold_Price, phi=est_gold$phi, theta = est_gold$theta, n.ahead=10, lastn=FALSE, limits=TRUE)

fore_arma = fore.arma.wge(gold$Gold_Price, phi=est_gold$phi, theta = est_gold$theta, n.ahead=30, lastn=FALSE, limits=TRUE)

f_short = fore.arma.wge(gold$Gold_Price, phi=est_gold$phi, theta = est_gold$theta,  n.ahead=10, lastn=TRUE, limits=TRUE)

f_long = fore.arma.wge(gold$Gold_Price, phi=est_gold$phi, theta = est_gold$theta,  n.ahead=30, lastn=TRUE, limits=TRUE)

ASE_short = mean((f_short$f - gold$Gold_Price[230:239])^2)
ASE_short
## [1] 23821474
# 23,821,474  # better than arima (26,159,247)

ASE_long = mean((f_long$f - gold$Gold_Price[210:239])^2)
ASE_long
## [1] 65786927
# 65,786,927   # worse than arima (52,383,904)
##Model ARIMA
##Because sample autocorrelations are slowly dampening ,there exists a non stationary and wandering behavior,let us try doing first order difference and model
firstdif = artrans.wge(gold$Gold_Price,1)

##
pacf(firstdif)
##partial auto correlation shows all lags are within limit,so we can assume noise is white
plotts.wge(firstdif)
acf(firstdif)
parzen.wge(firstdif)

## $freq
##   [1] 0.004201681 0.008403361 0.012605042 0.016806723 0.021008403 0.025210084
##   [7] 0.029411765 0.033613445 0.037815126 0.042016807 0.046218487 0.050420168
##  [13] 0.054621849 0.058823529 0.063025210 0.067226891 0.071428571 0.075630252
##  [19] 0.079831933 0.084033613 0.088235294 0.092436975 0.096638655 0.100840336
##  [25] 0.105042017 0.109243697 0.113445378 0.117647059 0.121848739 0.126050420
##  [31] 0.130252101 0.134453782 0.138655462 0.142857143 0.147058824 0.151260504
##  [37] 0.155462185 0.159663866 0.163865546 0.168067227 0.172268908 0.176470588
##  [43] 0.180672269 0.184873950 0.189075630 0.193277311 0.197478992 0.201680672
##  [49] 0.205882353 0.210084034 0.214285714 0.218487395 0.222689076 0.226890756
##  [55] 0.231092437 0.235294118 0.239495798 0.243697479 0.247899160 0.252100840
##  [61] 0.256302521 0.260504202 0.264705882 0.268907563 0.273109244 0.277310924
##  [67] 0.281512605 0.285714286 0.289915966 0.294117647 0.298319328 0.302521008
##  [73] 0.306722689 0.310924370 0.315126050 0.319327731 0.323529412 0.327731092
##  [79] 0.331932773 0.336134454 0.340336134 0.344537815 0.348739496 0.352941176
##  [85] 0.357142857 0.361344538 0.365546218 0.369747899 0.373949580 0.378151261
##  [91] 0.382352941 0.386554622 0.390756303 0.394957983 0.399159664 0.403361345
##  [97] 0.407563025 0.411764706 0.415966387 0.420168067 0.424369748 0.428571429
## [103] 0.432773109 0.436974790 0.441176471 0.445378151 0.449579832 0.453781513
## [109] 0.457983193 0.462184874 0.466386555 0.470588235 0.474789916 0.478991597
## [115] 0.483193277 0.487394958 0.491596639 0.495798319 0.500000000
## 
## $pzgram
##   [1]  4.483206219  4.356212979  4.147454104  3.861876896  3.507642551
##   [6]  3.097372045  2.649580730  2.189796008  1.750319718  1.367173138
##  [11]  1.073281035  0.889230639  0.815970565  0.834147495  0.910675524
##  [16]  1.008418134  1.094215002  1.143256212  1.140407917  1.079899786
##  [21]  0.964389862  0.803751720  0.613435216  0.412087591  0.218368878
##  [26]  0.047518909 -0.091132974 -0.194515801 -0.263749362 -0.300716010
##  [31] -0.305110706 -0.273596122 -0.201691391 -0.087656335  0.063566338
##  [36]  0.238536631  0.416672345  0.574029665  0.687755317  0.739771723
##  [41]  0.719212158  0.623828753  0.460722118  0.246410624  0.005731712
##  [46] -0.231285556 -0.435057071 -0.583552210 -0.667924764 -0.693492971
##  [51] -0.675459788 -0.632017964 -0.578431908 -0.524158543 -0.473075194
##  [56] -0.425754669 -0.382432238 -0.345451886 -0.320400280 -0.315753615
##  [61] -0.341438877 -0.406968363 -0.519674881 -0.683227348 -0.896274834
##  [66] -1.150904596 -1.430707178 -1.708766810 -1.946996096 -2.099602232
##  [71] -2.123400444 -1.993506371 -1.715871914 -1.326967760 -0.880624041
##  [76] -0.431778218 -0.025750915  0.305421428  0.542315979  0.675969663
##  [81]  0.705772174  0.637842249  0.483749300  0.259218982 -0.017531912
##  [86] -0.327949707 -0.655444917 -0.986994509 -1.313045953 -1.625243508
##  [91] -1.912590566 -2.157855405 -2.336809944 -2.422615791 -2.395344940
##  [96] -2.252377172 -2.012895450 -1.713168569 -1.396174974 -1.101973089
## [101] -0.862406449 -0.699892707 -0.628429542 -0.655177398 -0.781696974
## [106] -1.004450925 -1.314460158 -1.696193748 -2.126068779 -2.571515555
## [111] -2.992373079 -3.346689550 -3.601278224 -3.743100540 -3.784323311
## [116] -3.757009687 -3.700929082 -3.651551771 -3.632384773
aic5.wge(artrans.wge(gold$Gold_Price,1), type = 'aic', p=0:15, q=0:5)
## ---------WORKING... PLEASE WAIT...

## Error in aic calculation at 5 3 
## Error in aic calculation at 10 2 
## Error in aic calculation at 11 5 
## Error in aic calculation at 15 4 
## Error in aic calculation at 15 5 
## Five Smallest Values of  aic 
##     p    q        aic
##     3    4   13.18855
##     6    3   13.20195
##     2    2   13.20295
##     1    2   13.20408
##     1    1   13.20454
##After doing first order difference and aic5 is performed then it picked p=3,q=4
##(ARIMA(p,d,q)=ARIMA(3,1,4))
est_gold_arima = est.arma.wge(firstdif, p=3, q=4)
##   
##   
## Coefficients of AR polynomial:  
## -0.0484 0.0016 0.9560 
## 
##                            AR Factor Table 
## Factor                 Roots                Abs Recip    System Freq 
## 1+1.0182B+0.9858B^2   -0.5164+-0.8647i      0.9929       0.3357
## 1-0.9698B              1.0312               0.9698       0.0000
##   
##   
##   
##   
## Coefficients of MA polynomial:  
## -0.2718 -0.1119 0.8313 0.1467 
## 
##                               MA FACTOR TABLE 
## Factor                 Roots                Abs Recip    System Freq 
## 1+0.9812B+0.9607B^2   -0.5107+-0.8832i      0.9801       0.3334
## 1-0.8824B              1.1332               0.8824       0.0000
## 1+0.1730B             -5.7802               0.1730       0.5000
##   
## 
##est_gold_burg = est.arma.wge(firstdif, p=2, q=1,type='burg')
##est_gold_mle = est.arma.wge(firstdif, p=2, q=1,type='mle')
#fore_arima = fore.aruma.wge(gold$Gold_Price, phi=est_gold_arima$phi, theta = #est_gold_arima$theta,d=1, n.ahead=50, lastn=TRUE, limits=TRUE)


fore_arima = fore.aruma.wge(gold$Gold_Price, phi=est_gold_arima$phi, theta = est_gold_arima$theta,d=1, n.ahead=10, lastn=FALSE, limits=TRUE)
## s= 0 
## ptot.res= 1 
## phitot.res 1 
## ptot.fore= 4 
## phitot.fore 0.9515996 0.05000354 0.954423 -0.9560261

fore_arima$f
##  [1] 54156.25 55499.34 56456.82 57302.96 58547.56 59404.06 60173.53 61327.54
##  [9] 62091.74 62792.25
fore_arima = fore.aruma.wge(gold$Gold_Price, phi=est_gold_arima$phi, theta = est_gold_arima$theta,d=1, n.ahead=30, lastn=FALSE, limits=TRUE)
## s= 0 
## ptot.res= 1 
## phitot.res 1 
## ptot.fore= 4 
## phitot.fore 0.9515996 0.05000354 0.954423 -0.9560261

fore_arima$f
##  [1] 54156.25 55499.34 56456.82 57302.96 58547.56 59404.06 60173.53 61327.54
##  [9] 62091.74 62792.25 63862.82 64542.73 65181.24 66174.92 66777.87 67360.70
## [17] 68283.45 68816.15 69349.06 70206.29 70674.93 71163.09 71959.75 72370.00
## [25] 72818.12 73558.72 73915.81 74328.12 75016.77 75325.48
#ASE = mean((f_mle$f - firstdif[190:239])^2)
#ASE

f_short = fore.aruma.wge(gold$Gold_Price, phi=est_gold_arima$phi, theta = est_gold_arima$theta, d=1, n.ahead=10, lastn=TRUE, limits=TRUE)
## s= 0 
## ptot.res= 1 
## phitot.res 1 
## ptot.fore= 4 
## phitot.fore 0.9515996 0.05000354 0.954423 -0.9560261

f_long = fore.aruma.wge(gold$Gold_Price, phi=est_gold_arima$phi, theta = est_gold_arima$theta, d=1, n.ahead=30, lastn=TRUE, limits=TRUE)
## s= 0 
## ptot.res= 1 
## phitot.res 1 
## ptot.fore= 4 
## phitot.fore 0.9515996 0.05000354 0.954423 -0.9560261

ASE_short = mean((f_short$f - gold$Gold_Price[230:239])^2)
ASE_short
## [1] 26159247
# 26,159,247

ASE_long = mean((f_long$f - gold$Gold_Price[210:239])^2)
ASE_long
## [1] 52383904
# 52,383,904

mean(gold$Gold_Price)
## [1] 19299.06
est_gold_arima$avar
## [1] 499478.4
# COMMENTED OUT TO PREVENT MANY GRAPHS ON KNIT FILE
#roll.win.rmse.wge(gold$Gold_Price, horizon = 10, d = 1, phi = est_gold_arima$phi, theta = est_gold_arima$theta)
# "The Rolling Window RMSE is:  1759.087"

#roll.win.rmse.wge(gold$Gold_Price, horizon = 10, phi = est_gold$phi, theta = est_gold$theta)
# "The Rolling Window RMSE is:  1672.048"

#roll.win.rmse.wge(gold$Gold_Price, horizon = 30, d = 1, phi = est_gold_arima$phi, theta = est_gold_arima$theta)
# "The Rolling Window RMSE is:  3590.497"

#roll.win.rmse.wge(gold$Gold_Price, horizon = 30, phi = est_gold$phi, theta = est_gold$theta)
# "The Rolling Window RMSE is:  3307.673"
##After doing first order difference and aic5 is performed then it picked p=3,q=4
##(ARIMA(p,d,q)=ARIMA(6,1,3))
est_gold_arima_613 = est.arma.wge(firstdif, p=6, q=3)
##   
##   
## Coefficients of AR polynomial:  
## 0.1003 -0.0492 0.8882 -0.1435 0.0613 0.0599 
## 
##                            AR Factor Table 
## Factor                 Roots                Abs Recip    System Freq 
## 1+1.0191B+0.9828B^2   -0.5185+-0.8653i      0.9914       0.3359
## 1-0.9718B              1.0291               0.9718       0.0000
## 1-0.4555B+0.2039B^2    1.1169+-1.9123i      0.4515       0.1659
## 1+0.3079B             -3.2482               0.3079       0.5000
##   
##   
##   
##   
## Coefficients of MA polynomial:  
## -0.1207 -0.1156 0.8128 
## 
##                               MA FACTOR TABLE 
## Factor                 Roots                Abs Recip    System Freq 
## 1+0.9760B+0.9504B^2   -0.5135+-0.8880i      0.9749       0.3334
## 1-0.8553B              1.1692               0.8553       0.0000
##   
## 
##est_gold_burg = est.arma.wge(firstdif, p=2, q=1,type='burg')
##est_gold_mle = est.arma.wge(firstdif, p=2, q=1,type='mle')
#fore_arima = fore.aruma.wge(gold$Gold_Price, phi=est_gold_arima$phi, theta = #est_gold_arima$theta,d=1, n.ahead=50, lastn=TRUE, limits=TRUE)


fore_arima = fore.aruma.wge(gold$Gold_Price, phi=est_gold_arima_613$phi, theta = est_gold_arima_613$theta,d=1, n.ahead=10, lastn=FALSE, limits=TRUE)
## s= 0 
## ptot.res= 1 
## phitot.res 1 
## ptot.fore= 7 
## phitot.fore 1.100294 -0.149478 0.9373429 -1.03162 0.2047426 -0.00133102 -0.05994992

fore_arima$f
##  [1] 54217.42 55572.54 56504.26 57465.38 58872.84 59861.71 60772.64 62065.85
##  [9] 62941.87 63777.17
fore_arima = fore.aruma.wge(gold$Gold_Price, phi=est_gold_arima_613$phi, theta = est_gold_arima_613$theta,d=1, n.ahead=30, lastn=FALSE, limits=TRUE)
## s= 0 
## ptot.res= 1 
## phitot.res 1 
## ptot.fore= 7 
## phitot.fore 1.100294 -0.149478 0.9373429 -1.03162 0.2047426 -0.00133102 -0.05994992

fore_arima$f
##  [1] 54217.42 55572.54 56504.26 57465.38 58872.84 59861.71 60772.64 62065.85
##  [9] 62941.87 63777.17 64980.74 65767.98 66537.81 67656.63 68361.22 69071.47
## [17] 70111.70 70740.74 71397.12 72364.26 72924.20 73531.84 74430.96 74927.75
## [25] 75491.32 76327.09 76766.24 77289.97 78066.69 78453.28
#ASE = mean((f_mle$f - firstdif[190:239])^2)
#ASE

f_short = fore.aruma.wge(gold$Gold_Price, phi=est_gold_arima_613$phi, theta = est_gold_arima_613$theta, d=1, n.ahead=10, lastn=TRUE, limits=TRUE)
## s= 0 
## ptot.res= 1 
## phitot.res 1 
## ptot.fore= 7 
## phitot.fore 1.100294 -0.149478 0.9373429 -1.03162 0.2047426 -0.00133102 -0.05994992

f_long = fore.aruma.wge(gold$Gold_Price, phi=est_gold_arima_613$phi, theta = est_gold_arima_613$theta, d=1, n.ahead=30, lastn=TRUE, limits=TRUE)
## s= 0 
## ptot.res= 1 
## phitot.res 1 
## ptot.fore= 7 
## phitot.fore 1.100294 -0.149478 0.9373429 -1.03162 0.2047426 -0.00133102 -0.05994992

ASE_short = mean((f_short$f - gold$Gold_Price[230:239])^2)
ASE_short
## [1] 23370059
# 23,370,059

ASE_long = mean((f_long$f - gold$Gold_Price[210:239])^2)
ASE_long
## [1] 52377965
# 52,377,965


mean(gold$Gold_Price)
## [1] 19299.06
est_gold_arima_613$avar
## [1] 497783.9
plot(seq(1,239,1), gold$Gold_Price, type = "l",xlim = c(0,240), ylab = "Gold Price", main = "10 Month Gold Price Forecast", xlab = "Month")
lines(seq(230,239,1), f_short$f, type = "l", col = "red")

plot(seq(1,239,1), gold$Gold_Price, type = "l",xlim = c(0,240),  ylab = "Gold Price", main = "30 Month Gold Price Forecast", xlab = "Month")
lines(seq(210,239,1), f_long$f, type = "l", col = "red")

# COMMENTED OUT TO REMOVE THE MANY GRAPHS FROM THE KNIT FILE
#roll.win.rmse.wge(gold$Gold_Price, horizon = 10, d = 1, phi = est_gold_arima_613$phi, theta = est_gold_arima_613$theta)
# "The Rolling Window RMSE is:  1701.072"

#roll.win.rmse.wge(gold$Gold_Price, horizon = 30, d = 1, phi = est_gold_arima_613$phi, theta = est_gold_arima_613$theta)
# "The Rolling Window RMSE is:  3465.115"
UNIVARIATE NEURAL NETWORK
gold30 = gold[1:209,]
gold10 = gold[1:229,]
#SHORT TERM UNIVARIATE NEURAL NET (LAST 10 MONTHS)

fit.mlp = mlp(ts(gold10$Gold_Price),reps = 20,comb = "mean")
fit.mlp 
## MLP fit with 5 hidden nodes and 20 repetitions.
## Series modelled in differences: D1.
## Univariate lags: (1)
## Forecast combined using the mean operator.
## MSE: 461698.9922.
plot(fit.mlp)

fore.mlp = forecast(fit.mlp, h = 10)
plot(fore.mlp)

#Plot
plot(seq(1,239,1), gold$Gold_Price, type = "l",xlim = c(0,240), ylab = "Gold Price", main = "10 Month Gold Price Forecast", xlab = "Month")
lines(seq(230,239,1), fore.mlp$mean, type = "l", col = "red")

roll.win.rmse.nn.wge(gold$Gold_Price, horizon=10, fit.mlp) # 1,506.033
## [1] 9
## [1] 221
## [1] "Please Hold For a Moment, TSWGE is processing the Rolling Window RMSE with 221 windows."
## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## [1] "The Summary Statistics for the Rolling Window RMSE Are:"
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   207.7   709.0  1159.6  1541.5  1853.8  6837.1 
## [1] "The Rolling Window RMSE is:  1541.476"
#LONG TERM UNIVARIATE NEURAL NET (LAST 30 MONTHS)

fit.mlp = mlp(ts(gold30$Gold_Price),reps = 20,comb = "mean")
## Warning in preprocess(y, m, lags, keep, difforder, sel.lag, allow.det.season, :
## No inputs left in the network after pre-selection, forcing AR(1).
fit.mlp 
## MLP fit with 5 hidden nodes and 20 repetitions.
## Series modelled in differences: D1.
## Univariate lags: (1)
## Forecast combined using the mean operator.
## MSE: 430104.457.
plot(fit.mlp)

fore.mlp = forecast(fit.mlp, h = 30)
plot(fore.mlp)

#Plot
plot(seq(1,239,1), gold$Gold_Price, type = "l",xlim = c(0,240), ylab = "Gold Price", main = "30 Month Gold Price Forecast", xlab = "Month")
lines(seq(210,239,1), fore.mlp$mean, type = "l", col = "red")

roll.win.rmse.nn.wge(gold$Gold_Price, horizon=30, fit.mlp) #2,708.565
## [1] 9
## [1] 201
## [1] "Please Hold For a Moment, TSWGE is processing the Rolling Window RMSE with 201 windows."
## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.
## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## [1] "The Summary Statistics for the Rolling Window RMSE Are:"
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   660.8  1219.9  1877.1  2617.1  3652.8  7075.3 
## [1] "The Rolling Window RMSE is:  2617.064"
#SHORT TERM UNIVARIATE NEURAL NET (AHEAD)

fit.mlp = mlp(ts(gold$Gold_Price),reps = 20,comb = "mean")
fit.mlp 
## MLP fit with 5 hidden nodes and 20 repetitions.
## Series modelled in differences: D1.
## Univariate lags: (1,3)
## Forecast combined using the mean operator.
## MSE: 449111.1153.
plot(fit.mlp)

fore.mlp = forecast(fit.mlp, h = 10)
plot(fore.mlp)

#Plot
plot(seq(1,239,1), gold$Gold_Price, type = "l",xlim = c(0,250), ylim = c(0, 100000), ylab = "Gold Price", main = "10 Month Gold Price Forecast")
lines(seq(240,249,1), fore.mlp$mean, type = "l", col = "red")

roll.win.rmse.nn.wge(gold$Gold_Price, horizon=10, fit.mlp) # 1,506.033
## [1] 9
## [1] 221
## [1] "Please Hold For a Moment, TSWGE is processing the Rolling Window RMSE with 221 windows."
## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## [1] "The Summary Statistics for the Rolling Window RMSE Are:"
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   94.85  630.09 1171.13 1515.32 2018.06 6460.60 
## [1] "The Rolling Window RMSE is:  1515.323"
#LONG TERM UNIVARIATE NEURAL NET (AHEAD)
#forecast cmort using mlp with forecasted xreg (don't need to forecast week.)

fit.mlp = mlp(ts(gold$Gold_Price),reps = 20,comb = "mean")
fit.mlp 
## MLP fit with 5 hidden nodes and 20 repetitions.
## Series modelled in differences: D1.
## Univariate lags: (1,3)
## Forecast combined using the mean operator.
## MSE: 447030.7464.
plot(fit.mlp)

fore.mlp = forecast(fit.mlp, h = 30)
plot(fore.mlp)

#Plot
plot(seq(1,239,1), gold$Gold_Price, type = "l",xlim = c(0,250), ylim = c(0, 100000), ylab = "Gold Price", main = "10 Month Gold Price Forecast")
lines(seq(240,269,1), fore.mlp$mean, type = "l", col = "red")

roll.win.rmse.nn.wge(gold$Gold_Price, horizon=30, fit.mlp) #2,708.565
## [1] 9
## [1] 201
## [1] "Please Hold For a Moment, TSWGE is processing the Rolling Window RMSE with 201 windows."
## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## Warning in predict.mlp(fit, h = horizon): Use forecast() instead of predict()
## for MLP.

## [1] "The Summary Statistics for the Rolling Window RMSE Are:"
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   275.2  1173.0  2061.5  2691.8  3800.2  8834.8 
## [1] "The Rolling Window RMSE is:  2691.77"
MULTIVARIATE (VAR, NN, ENSEMBLE) LONG TERM (NOT AHEAD - FORECASTING LAST 30 MONTHS)
#Long term VAR
gold30 = gold[1:209,]

X =(cbind(gold30$Gold_Price, gold30$Crude_Oil, gold30$Interest_Rate, gold30$CPI, gold30$USD_Index)) #

VARselect(X, lag.max=10, type='const', season=NULL, exogen=NULL)
## $selection
## AIC(n)  HQ(n)  SC(n) FPE(n) 
##      2      1      1      2 
## 
## $criteria
##                   1            2            3            4            5
## AIC(n) 2.200804e+01 2.189992e+01 2.191931e+01 2.202441e+01 2.202234e+01
## HQ(n)  2.220898e+01 2.226831e+01 2.245514e+01 2.272769e+01 2.289307e+01
## SC(n)  2.250452e+01 2.281013e+01 2.324325e+01 2.376208e+01 2.417375e+01
## FPE(n) 3.614180e+09 3.245335e+09 3.312771e+09 3.688010e+09 3.693558e+09
##                   6            7            8            9           10
## AIC(n) 2.206294e+01 2.219654e+01 2.208935e+01 2.209010e+01 2.212630e+01
## HQ(n)  2.310112e+01 2.340216e+01 2.346243e+01 2.363062e+01 2.383427e+01
## SC(n)  2.462808e+01 2.517541e+01 2.548195e+01 2.589643e+01 2.634637e+01
## FPE(n) 3.866938e+09 4.452224e+09 4.039036e+09 4.093405e+09 4.312276e+09
#Varselect picks p=2
lsfit=VAR(cbind(gold30$Gold_Price, gold30$Crude_Oil, gold30$Interest_Rate, gold30$CPI, gold30$USD_Index), p=2, type='const') #
## Warning in VAR(cbind(gold30$Gold_Price, gold30$Crude_Oil, gold30$Interest_Rate, : No column names supplied in y, using: y1, y2, y3, y4, y5 , instead.
preds=predict(lsfit, n.ahead=30)
preds
## $y1
##           fcst    lower    upper       CI
##  [1,] 30541.48 29252.22 31830.73 1289.257
##  [2,] 30758.81 28874.84 32642.77 1883.965
##  [3,] 31000.30 28685.77 33314.83 2314.529
##  [4,] 31238.14 28566.42 33909.86 2671.722
##  [5,] 31469.68 28484.05 34455.31 2985.631
##  [6,] 31696.13 28427.37 34964.88 3268.755
##  [7,] 31918.24 28390.11 35446.36 3528.125
##  [8,] 32136.43 28368.15 35904.71 3768.281
##  [9,] 32351.01 28358.68 36343.33 3992.326
## [10,] 32562.21 28359.74 36764.68 4202.471
## [11,] 32770.23 28369.86 37170.59 4400.366
## [12,] 32975.22 28387.94 37562.50 4587.282
## [13,] 33177.31 28413.08 37941.55 4764.233
## [14,] 33376.62 28444.57 38308.68 4932.055
## [15,] 33573.25 28481.80 38664.70 5091.450
## [16,] 33767.28 28524.26 39010.31 5243.028
## [17,] 33958.81 28571.49 39346.13 5387.321
## [18,] 34147.91 28623.10 39672.72 5524.810
## [19,] 34334.66 28678.73 39990.58 5655.926
## [20,] 34519.13 28738.07 40300.20 5781.067
## [21,] 34701.41 28800.81 40602.01 5900.600
## [22,] 34881.57 28866.70 40896.43 6014.864
## [23,] 35059.67 28935.49 41183.85 6124.178
## [24,] 35235.80 29006.96 41464.64 6228.837
## [25,] 35410.03 29080.91 41739.15 6329.121
## [26,] 35582.42 29157.13 42007.71 6425.290
## [27,] 35753.06 29235.47 42270.65 6517.592
## [28,] 35922.01 29315.75 42528.26 6606.256
## [29,] 36089.34 29397.84 42780.84 6691.500
## [30,] 36255.12 29481.59 43028.65 6773.528
## 
## $y2
##           fcst    lower    upper        CI
##  [1,] 3987.136 3529.223 4445.048  457.9126
##  [2,] 3948.077 3198.934 4697.220  749.1428
##  [3,] 3946.322 2996.612 4896.032  949.7102
##  [4,] 3963.103 2875.677 5050.528 1087.4252
##  [5,] 3989.342 2802.185 5176.500 1187.1577
##  [6,] 4020.785 2755.401 5286.168 1265.3836
##  [7,] 4055.138 2723.252 5387.025 1331.8866
##  [8,] 4091.015 2698.911 5483.119 1392.1040
##  [9,] 4127.515 2678.663 5576.367 1448.8521
## [10,] 4164.028 2660.581 5667.476 1503.4472
## [11,] 4200.128 2643.737 5756.520 1556.3915
## [12,] 4235.512 2627.736 5843.289 1607.7763
## [13,] 4269.968 2612.459 5927.477 1657.5088
## [14,] 4303.346 2597.912 6008.780 1705.4339
## [15,] 4335.546 2584.150 6086.943 1751.3964
## [16,] 4366.504 2571.235 6161.773 1795.2690
## [17,] 4396.184 2559.221 6233.147 1836.9628
## [18,] 4424.571 2548.143 6300.999 1876.4277
## [19,] 4451.665 2538.016 6365.314 1913.6493
## [20,] 4477.481 2528.837 6426.124 1948.6434
## [21,] 4502.040 2520.590 6483.491 1981.4505
## [22,] 4525.374 2513.243 6537.505 2012.1307
## [23,] 4547.516 2506.757 6588.275 2040.7588
## [24,] 4568.506 2501.086 6635.926 2067.4201
## [25,] 4588.386 2496.178 6680.593 2092.2075
## [26,] 4607.198 2491.980 6722.417 2115.2183
## [27,] 4624.988 2488.436 6761.541 2136.5523
## [28,] 4641.801 2485.491 6798.111 2156.3096
## [29,] 4657.682 2483.093 6832.272 2174.5896
## [30,] 4672.677 2481.187 6864.166 2191.4894
## 
## $y3
##           fcst    lower    upper        CI
##  [1,] 6.325615 5.739161 6.912069 0.5864540
##  [2,] 6.429384 5.623132 7.235636 0.8062517
##  [3,] 6.512852 5.579528 7.446175 0.9333234
##  [4,] 6.580639 5.557998 7.603280 1.0226407
##  [5,] 6.639586 5.546630 7.732543 1.0929566
##  [6,] 6.692921 5.541225 7.844616 1.1516951
##  [7,] 6.742217 5.539601 7.944833 1.2026161
##  [8,] 6.788430 5.540471 8.036389 1.2479594
##  [9,] 6.832197 5.542997 8.121398 1.2892006
## [10,] 6.873958 5.546578 8.201338 1.3273800
## [11,] 6.914021 5.550765 8.277277 1.3632562
## [12,] 6.952602 5.555219 8.349985 1.3973826
## [13,] 6.989855 5.559702 8.420008 1.4301531
## [14,] 7.025890 5.564055 8.487725 1.4618351
## [15,] 7.060785 5.568188 8.553382 1.4925969
## [16,] 7.094595 5.572063 8.617126 1.5225312
## [17,] 7.127360 5.575684 8.679035 1.5516753
## [18,] 7.159110 5.579081 8.739138 1.5800285
## [19,] 7.189867 5.582301 8.797432 1.6075654
## [20,] 7.219649 5.585402 8.853896 1.6342471
## [21,] 7.248473 5.588444 8.908502 1.6600293
## [22,] 7.276352 5.591484 8.961221 1.6848684
## [23,] 7.303301 5.594576 9.012027 1.7087254
## [24,] 7.329334 5.597766 9.060903 1.7315681
## [25,] 7.354467 5.601093 9.107840 1.7533733
## [26,] 7.378714 5.604587 9.152841 1.7741267
## [27,] 7.402094 5.608271 9.195917 1.7938230
## [28,] 7.424624 5.612158 9.237089 1.8124655
## [29,] 7.446324 5.616258 9.276389 1.8300656
## [30,] 7.467213 5.620572 9.313854 1.8466414
## 
## $y4
##           fcst    lower    upper       CI
##  [1,] 109.8718 108.8558 110.8877 1.015969
##  [2,] 110.0875 108.4736 111.7014 1.613866
##  [3,] 110.3548 108.2746 112.4349 2.080145
##  [4,] 110.6504 108.1828 113.1180 2.467629
##  [5,] 110.9639 108.1597 113.7680 2.804125
##  [6,] 111.2898 108.1840 114.3956 3.105800
##  [7,] 111.6256 108.2430 115.0083 3.382625
##  [8,] 111.9697 108.3286 115.6107 3.641048
##  [9,] 112.3208 108.4354 116.2063 3.885453
## [10,] 112.6784 108.5595 116.7974 4.118957
## [11,] 113.0419 108.6980 117.3857 4.343871
## [12,] 113.4107 108.8487 117.9726 4.561966
## [13,] 113.7844 109.0098 118.5590 4.774631
## [14,] 114.1627 109.1798 119.1457 4.982978
## [15,] 114.5454 109.3575 119.7333 5.187904
## [16,] 114.9320 109.5418 120.3221 5.390144
## [17,] 115.3224 109.7321 120.9127 5.590296
## [18,] 115.7163 109.9274 121.5051 5.788846
## [19,] 116.1134 110.1272 122.0996 5.986192
## [20,] 116.5137 110.3310 122.6963 6.182651
## [21,] 116.9168 110.5384 123.2953 6.378475
## [22,] 117.3227 110.7488 123.8966 6.573860
## [23,] 117.7311 110.9621 124.5000 6.768951
## [24,] 118.1418 111.1780 125.1057 6.963855
## [25,] 118.5548 111.3961 125.7134 7.158643
## [26,] 118.9697 111.6164 126.3231 7.353356
## [27,] 119.3866 111.8386 126.9346 7.548010
## [28,] 119.8053 112.0627 127.5479 7.742600
## [29,] 120.2256 112.2885 128.1627 7.937106
## [30,] 120.6474 112.5159 128.7789 8.131492
## 
## $y5
##           fcst    lower     upper        CI
##  [1,] 90.62349 86.48234  94.76465  4.141158
##  [2,] 90.46374 84.63589  96.29158  5.827846
##  [3,] 90.28216 83.23339  97.33094  7.048778
##  [4,] 90.10613 82.08720  98.12507  8.018934
##  [5,] 89.93821 81.10674  98.76968  8.831468
##  [6,] 89.78017 80.24536  99.31498  9.534811
##  [7,] 89.63327 79.47567  99.79086 10.157592
##  [8,] 89.49806 78.78017 100.21594 10.717887
##  [9,] 89.37468 78.14709 100.60227 11.227591
## [10,] 89.26305 77.56823 100.95787 11.694819
## [11,] 89.16299 77.03768 101.28830 12.125312
## [12,] 89.07422 76.55094 101.59751 12.523284
## [13,] 88.99645 76.10450 101.88840 12.891950
## [14,] 88.92932 75.69545 102.16318 13.233865
## [15,] 88.87246 75.32133 102.42360 13.551137
## [16,] 88.82550 74.97993 102.67108 13.845573
## [17,] 88.78804 74.66927 102.90680 14.118764
## [18,] 88.75965 74.38750 103.13180 14.372150
## [19,] 88.73994 74.13289 103.34700 14.607058
## [20,] 88.72849 73.90377 103.55321 14.824724
## [21,] 88.72488 73.69857 103.75119 15.026312
## [22,] 88.72870 73.51578 103.94162 15.212921
## [23,] 88.73954 73.35394 104.12513 15.385594
## [24,] 88.75700 73.21168 104.30232 15.545317
## [25,] 88.78069 73.08766 104.47371 15.693027
## [26,] 88.81022 72.98061 104.63983 15.829608
## [27,] 88.84522 72.88932 104.80111 15.955895
## [28,] 88.88532 72.81264 104.95799 16.072673
## [29,] 88.93017 72.74949 105.11085 16.180678
## [30,] 88.97943 72.69883 105.26003 16.280601
preds$fcst$y1[1:30,1]
##  [1] 30541.48 30758.81 31000.30 31238.14 31469.68 31696.13 31918.24 32136.43
##  [9] 32351.01 32562.21 32770.23 32975.22 33177.31 33376.62 33573.25 33767.28
## [17] 33958.81 34147.91 34334.66 34519.13 34701.41 34881.57 35059.67 35235.80
## [25] 35410.03 35582.42 35753.06 35922.01 36089.34 36255.12
plot(seq(1,239,1), gold$Gold_Price, type='l', main = "30 Month Gold Price Forecast", ylab="Gold Price", xlab="Month") #ylim=c(0,6)
points(seq(210,239,1),preds$fcst$y1[1:30,1], pch=15, col='red', type='l')

fanchart(preds)

fanchart(preds, names='y1')

ASE = mean((preds$fcst$y1[1:30,1]-gold$Gold_Price[210:239])^2)
ASE #33,167,267
## [1] 33167267
#roll.win.rmse.nn.wge(gold$Gold_Price, horizon=30)
# Long Term MLP
#gold30 is the gold data from 1-209, leaving out 210-239

#forecast crude oil, interest rate, cpi, and usd index

#crude
fit.mlp.crude = mlp(ts(gold30$Crude_Oil),reps = 20, comb = "mean")
plot(fit.mlp.crude)

fore.mlp.crude = forecast(fit.mlp.crude, h = 30)
plot(fore.mlp.crude)

#interest
fit.mlp.int = mlp(ts(gold30$Interest_Rate),reps = 20, comb = "mean")
fore.mlp.int = forecast(fit.mlp.int, h = 30)
plot(fore.mlp.int)

#CPI
fit.mlp.cpi = mlp(ts(gold30$CPI),reps = 20, comb = "mean")
plot(fit.mlp.cpi)

fore.mlp.cpi = forecast(fit.mlp.cpi, h = 30)
plot(fore.mlp.cpi)

#USD
fit.mlp.usd = mlp(ts(gold30$USD_Index),reps = 20, comb = "mean")
fore.mlp.usd = forecast(fit.mlp.usd, h = 30)
plot(fore.mlp.usd)

#package them up in data frame.
#fore.mlp.temp1 = dplyr::lag(as.vector(fore.mlp.temp$mean),1)
GDF_fore = data.frame(Month = ts(seq(1,239,1)),crude_oil = ts(c(gold30$Crude_Oil,fore.mlp.crude$mean)), interest_rate = ts(c(gold30$Interest_Rate,fore.mlp.int$mean)), CPI = ts(c(gold30$CPI,fore.mlp.cpi$mean)), USD_index = ts(c(gold30$USD_Index,fore.mlp.usd$mean)))
GDF_fore
##     Month crude_oil interest_rate      CPI USD_index
## 1       1  1455.510      8.000000  37.2300 116.65000
## 2       2  1512.470      8.000000  37.3100 115.24000
## 3       3  1178.110      8.000000  36.9800 109.56000
## 4       4  1208.180      8.000000  36.9000 110.52000
## 5       5  1267.180      7.500000  36.7300 112.01000
## 6       6  1166.450      7.000000  36.9000 117.37000
## 7       7  1203.330      7.000000  37.1500 115.85000
## 8       8  1292.570      7.000000  37.4000 119.07000
## 9       9  1267.730      7.000000  37.8900 119.43000
## 10     10  1169.120      7.000000  38.3900 117.18000
## 11     11  1216.800      7.000000  38.6400 113.42000
## 12     12  1201.160      7.000000  38.5600 113.48000
## 13     13   995.460      6.500000  38.8000 114.86000
## 14     14   897.070      6.500000  39.1400 116.13000
## 15     15   887.420      6.500000  38.8900 116.75000
## 16     16   925.630      6.500000  38.7200 120.24000
## 17     17   972.860      6.500000  38.6400 119.16000
## 18     18  1152.200      6.500000  38.8000 118.62000
## 19     19  1244.020      6.500000  38.8900 115.19000
## 20     20  1257.830      6.500000  39.1400 111.81000
## 21     21  1199.060      6.500000  39.4700 106.11000
## 22     22  1255.670      6.500000  39.8800 107.41000
## 23     23  1301.250      6.500000  40.1300 106.98000
## 24     24  1369.920      6.500000  40.2100 106.87000
## 25     25  1331.610      6.500000  40.3800 106.64000
## 26     26  1184.180      6.250000  40.5500 106.41000
## 27     27  1342.560      6.250000  40.1300 101.85000
## 28     28  1473.850      6.250000  40.0500  99.91000
## 29     29  1569.550      6.250000  40.1300  99.71000
## 30     30  1446.380      6.250000  40.3800  99.06000
## 31     31  1210.970      6.250000  40.8800  97.19000
## 32     32  1226.990      6.000000  40.9600  93.27000
## 33     33  1304.450      6.000000  41.2100  94.73000
## 34     34  1321.850      6.000000  41.5400  96.89000
## 35     35  1363.370      6.000000  41.3800  98.10000
## 36     36  1232.460      6.000000  41.3800  92.85000
## 37     37  1316.780      6.000000  41.7100  92.73000
## 38     38  1325.540      6.000000  41.7900  90.21000
## 39     39  1366.360      6.000000  41.6200  86.92000
## 40     40  1425.740      6.000000  41.7900  87.20000
## 41     41  1418.360      6.000000  41.7900  87.31000
## 42     42  1515.650      6.000000  41.7900  87.61000
## 43     43  1480.990      6.000000  41.7900  90.48000
## 44     44  1699.290      6.000000  42.1200  88.95000
## 45     45  1617.640      6.000000  42.4500  88.80000
## 46     46  1744.590      6.000000  42.8700  89.96000
## 47     47  1950.090      6.000000  43.2800  88.94000
## 48     48  1917.680      6.000000  43.3700  87.36000
## 49     49  2146.340      6.000000  43.6100  84.91000
## 50     50  1900.580      6.000000  43.5300  81.82000
## 51     51  1717.000      6.000000  43.2000  80.85000
## 52     52  1880.230      6.000000  43.6100  83.60000
## 53     53  1957.600      6.000000  43.5300  82.51000
## 54     54  2225.570      6.000000  43.5300  84.06000
## 55     55  2215.050      6.000000  43.8600  84.43000
## 56     56  2080.200      6.000000  43.7000  87.76000
## 57     57  2348.850      6.000000  43.8600  89.11000
## 58     58  2454.200      6.000000  44.6100  89.35000
## 59     59  2700.010      6.000000  44.7700  87.58000
## 60     60  2709.210      6.000000  44.9400  89.52000
## 61     61  2608.220      6.000000  45.4400  90.07000
## 62     62  2516.770      6.000000  45.8500  91.57000
## 63     63  2576.490      6.000000  45.6000  91.17000
## 64     64  2773.130      6.000000  45.5200  88.96000
## 65     65  2646.560      6.000000  45.5200  90.11000
## 66     66  2709.890      6.000000  45.5200  89.73000
## 67     67  3055.210      6.000000  45.9000  86.11000
## 68     68  3118.700      6.000000  46.2900  84.72000
## 69     69  3145.130      6.000000  47.0500  85.22000
## 70     70  3365.750      6.000000  47.4300  85.30000
## 71     71  3341.970      6.000000  47.4300  85.05000
## 72     72  2865.030      6.000000  47.8200  85.97000
## 73     73  2633.080      6.000000  48.5800  85.32000
## 74     74  2607.990      6.000000  48.5800  82.92000
## 75     75  2722.260      6.000000  48.5800  83.72000
## 76     76  2373.050      6.000000  48.5800  84.61000
## 77     77  2541.990      6.000000  48.9600  83.57000
## 78     78  2667.950      6.000000  48.5800  82.93000
## 79     79  2742.350      6.000000  48.9600  81.45000
## 80     80  2658.010      6.000000  49.3500  82.30000
## 81     81  2779.560      6.000000  49.7300  81.92000
## 82     82  2974.640      6.000000  50.4900  80.77000
## 83     83  2862.540      6.000000  50.8800  80.79000
## 84     84  3096.500      6.000000  50.8800  77.72000
## 85     85  3238.900      6.000000  51.2600  76.48000
## 86     86  3602.450      6.000000  51.2600  76.15000
## 87     87  3530.670      6.000000  51.2600  76.69000
## 88     88  3570.710      6.000000  51.2600  75.18000
## 89     89  3710.340      6.000000  51.6400  73.71000
## 90     90  4109.920      6.000000  52.4100  71.80000
## 91     91  4353.720      6.000000  52.7900  72.51000
## 92     92  5165.850      6.000000  53.1700  72.88000
## 93     93  5631.690      6.000000  53.5500  72.46000
## 94     94  5689.980      6.000000  54.7000  73.23000
## 95     95  4919.520      6.000000  55.4700  77.38000
## 96     96  4540.910      6.000000  55.8500  79.45000
## 97     97  3535.800      6.000000  56.6100  85.63000
## 98     98  2644.710      6.000000  56.6100  86.52000
## 99     99  2010.860      6.000000  56.2300  81.15000
## 100   100  2142.120      6.000000  56.6100  85.83000
## 101   101  2059.460      6.000000  56.6100  88.17000
## 102   102  2391.750      6.000000  56.6100  85.51000
## 103   103  2517.580      6.000000  57.3800  84.82000
## 104   104  2822.250      6.000000  57.7600  79.23000
## 105   105  3303.550      6.000000  58.5300  80.16000
## 106   106  3137.000      6.000000  61.2000  78.35000
## 107   107  3461.090      6.000000  61.9700  78.17000
## 108   108  3310.800      6.000000  62.3500  76.65000
## 109   109  3461.100      6.000000  63.1200  76.30000
## 110   110  3611.430      6.000000  64.2700  74.78000
## 111   111  3491.650      6.000000  64.6500  77.86000
## 112   112  3541.880      6.000000  65.8000  79.46000
## 113   113  3463.320      6.000000  65.0300  80.36000
## 114   114  3607.990      6.000000  65.0300  81.07000
## 115   115  3745.920      6.000000  65.0300  81.87000
## 116   116  3461.170      6.000000  65.8000  86.59000
## 117   117  3479.770      6.000000  66.5600  86.02000
## 118   118  3495.720      6.000000  68.0900  81.54000
## 119   119  3531.140      6.000000  68.0900  83.20000
## 120   120  3504.320      6.000000  68.4700  78.72000
## 121   121  3629.800      6.000000  69.2400  77.27000
## 122   122  3793.460      6.000000  69.6200  81.19000
## 123   123  4065.660      6.000000  70.7700  79.03000
## 124   124  4206.660      6.000000  71.9200  77.73000
## 125   125  4450.500      6.000000  70.7700  76.89000
## 126   126  4888.110      6.000000  70.7700  75.86000
## 127   127  5159.400      6.000000  71.1500  72.93000
## 128   128  4851.800      6.000000  71.5300  74.64000
## 129   129  4747.570      6.000000  72.3000  74.30000
## 130   130  4793.300      6.000000  73.8300  73.90000
## 131   131  4550.040      6.000000  74.2100  74.12000
## 132   132  4811.930      6.000000  75.3600  78.55000
## 133   133  4916.610      6.000000  75.7400  76.17000
## 134   134  5343.290      6.000000  76.1200  78.38000
## 135   135  5486.720      6.000000  75.3600  80.18000
## 136   136  5484.920      6.000000  75.7400  79.29000
## 137   137  5540.260      9.500000  76.1200  78.74000
## 138   138  5927.550      9.500000  76.8900  79.00000
## 139   139  5888.490      9.000000  78.4200  78.78000
## 140   140  5655.940      9.000000  78.8000  83.04000
## 141   141  5083.600      9.000000  79.5700  81.63000
## 142   142  5372.190      9.000000  81.1000  82.64000
## 143   143  5848.750      9.000000  81.8600  81.21000
## 144   144  5798.480      9.000000  82.2400  79.94000
## 145   145  5476.430      9.000000  83.0100  79.92000
## 146   146  5536.010      9.000000  83.3900  80.15000
## 147   147  5526.620      9.000000  83.7700  79.77000
## 148   148  5708.320      9.000000  84.5400  79.21000
## 149   149  5784.940      8.750000  85.3000  81.95000
## 150   150  5575.840      8.500000  85.6900  83.22000
## 151   151  5375.040      8.500000  86.4500  81.75000
## 152   152  5468.660      8.250000  87.2200  83.26000
## 153   153  5817.690      8.250000  88.3600  83.14000
## 154   154  6292.380     10.250000  89.8900  81.45000
## 155   155  6836.670     10.250000  90.6600  82.09000
## 156   156  6926.830      9.500000  91.0400  80.22000
## 157   157  6497.770      8.750000  92.1900  80.19000
## 158   158  6435.780      8.750000  92.9600  80.68000
## 159   159  6534.280      8.750000  91.4200  80.03000
## 160   160  6344.000      9.000000  90.6600  81.31000
## 161   161  6529.280      9.000000  91.0400  79.69000
## 162   162  6343.000      9.000000  91.4200  80.10000
## 163   163  6329.600      9.000000  92.5700  79.47000
## 164   164  6273.130      9.000000  93.3400  80.37000
## 165   165  6471.050      9.000000  94.1000  79.78000
## 166   166  6320.510      9.000000  96.4000  81.46000
## 167   167  6092.560      9.000000  96.7800  82.75000
## 168   168  5835.690      9.000000  96.7800  85.94000
## 169   169  5280.840      9.000000  96.7800  86.92000
## 170   170  4748.530      9.000000  96.7800  88.36000
## 171   171  3806.550      9.000000  96.7800  90.27000
## 172   172  2927.200      8.750000  97.1600  94.80000
## 173   173  3398.510      8.750000  96.7800  95.32000
## 174   174  3299.230      8.500000  97.1600  98.36000
## 175   175  3611.030      8.500000  97.9300  94.60000
## 176   176  3988.780      8.500000  98.6900  96.91000
## 177   177  3915.300      8.250000  99.8400  95.48000
## 178   178  3458.510      8.250000 100.6100  97.34000
## 179   179  2973.160      8.250000 100.9900  95.82000
## 180   180  3064.430      8.250000 101.7500  96.35000
## 181   181  3055.950      7.750000 102.9000  96.95000
## 182   182  2847.430      7.750000 103.2800 100.17000
## 183   183  2435.400      7.750000 102.9000  98.63000
## 184   184  2004.000      7.750000 102.9000  99.61000
## 185   185  2117.580      7.750000 102.1400  98.21000
## 186   186  2503.950      7.750000 102.5200  94.59000
## 187   187  2708.630      7.000000 103.6700  93.08000
## 188   188  3072.750      7.000000 105.2000  95.89000
## 189   189  3208.660      7.000000 105.9600  96.14000
## 190   190  2966.280      7.000000 107.1100  95.53000
## 191   191  3004.160      7.000000 106.3400  96.02000
## 192   192  3006.050      7.000000 105.9600  95.46000
## 193   193  3290.460      6.750000 106.3400  98.44000
## 194   194  3056.290      6.750000 105.9600 101.50000
## 195   195  3572.840      6.750000 105.2000 102.21000
## 196   196  3649.890      6.750000 104.8100  99.51000
## 197   197  3647.030      6.750000 104.8100 101.12000
## 198   198  3355.090      6.750000 105.2000 100.35000
## 199   199  3365.040      6.500000 105.9600  99.05000
## 200   200  3213.830      6.500000 106.3400  96.92000
## 201   201  2975.010      6.500000 107.1100  95.63000
## 202   202  3071.230      6.500000 109.0200  92.86000
## 203   203  3194.460      6.250000 109.0200  92.67000
## 204   204  3413.190      6.250000 109.0200  93.08000
## 205   205  3574.530      6.250000 109.7900  94.55000
## 206   206  3887.810      6.250000 110.1700  93.05000
## 207   207  3930.990      6.250000 109.4000  92.12000
## 208   208  4215.160      6.250000 110.1700  89.13000
## 209   209  4085.160      6.250000 109.7900  90.61000
## 210   210  4066.438      6.232093 110.1759  90.23197
## 211   211  4082.450      6.217134 111.3033  89.85497
## 212   212  4108.430      6.207447 111.9980  89.47984
## 213   213  4137.222      6.199604 112.9054  89.10747
## 214   214  4166.807      6.192912 113.6374  88.73879
## 215   215  4196.619      6.187523 113.8998  88.37473
## 216   216  4226.495      6.183220 114.3589  88.01626
## 217   217  4256.389      6.179729 114.7813  87.66432
## 218   218  4286.289      6.176883 115.1196  87.31985
## 219   219  4316.191      6.174563 115.5371  86.98374
## 220   220  4346.093      6.172666 115.8560  86.65683
## 221   221  4375.995      6.171106 116.0835  86.33990
## 222   222  4405.897      6.169819 116.3259  86.03363
## 223   223  4435.799      6.168752 116.4989  85.73862
## 224   224  4465.701      6.167865 116.6667  85.45536
## 225   225  4495.603      6.167125 116.8161  85.18424
## 226   226  4525.505      6.166504 116.9166  84.92552
## 227   227  4555.407      6.165982 117.0316  84.67938
## 228   228  4585.309      6.165541 117.1627  84.44586
## 229   229  4615.211      6.165169 117.2565  84.22492
## 230   230  4645.113      6.164852 117.3488  84.01642
## 231   231  4675.015      6.164582 117.4566  83.82012
## 232   232  4704.918      6.164352 117.5214  83.63573
## 233   233  4734.820      6.164155 117.5952  83.46289
## 234   234  4764.722      6.163986 117.6917  83.30119
## 235   235  4794.624      6.163841 117.7398  83.15018
## 236   236  4824.526      6.163716 117.8137  83.00939
## 237   237  4854.428      6.163608 117.9072  82.87830
## 238   238  4884.330      6.163515 117.9683  82.75641
## 239   239  4914.232      6.163434 118.0562  82.64322
#forecast cmort using mlp with forecasted xreg (don't need to forecast week.)
gold30DF = data.frame(Date = ts(seq(1,209,1)),crude_oil = ts(gold30$Crude_Oil), interest_rate = ts(gold30$Interest_Rate), CPI = ts(gold30$CPI),  USD_index = ts(gold30$USD_Index))
fit.mlp = mlp(ts(gold30$Gold_Price),reps = 20,comb = "mean",xreg = gold30DF)
fit.mlp
## MLP fit with 5 hidden nodes and 20 repetitions.
## Series modelled in differences: D1.
## Univariate lags: (1,2,3,4)
## 4 regressors included.
## - Regressor 1 lags: (3,4)
## - Regressor 2 lags: (4)
## - Regressor 3 lags: (1,4)
## - Regressor 4 lags: (1,3)
## Forecast combined using the mean operator.
## MSE: 83775.241.
plot(fit.mlp)

#CMDF = data.frame(Week = ts(CM$Week),temp = ts(CM$temp), part = ts(CM$part), temp_1 = ts(CM$temp_1))
fore.mlp = forecast(fit.mlp, h = 30, xreg = GDF_fore)
plot(fore.mlp)

ASE = mean((gold$Gold_Price[210:239] - fore.mlp$mean)^2)
ASE #46,958,703
## [1] 26519215
#Plot
plot(seq(1,239,1), gold$Gold_Price, type = "l",xlim = c(0,250), main = "30 Month Gold Price Forecast MLP", ylab="Gold Price", xlab="Month")
lines(seq(210,239,1), fore.mlp$mean, type = "l", col = "red")

#roll.win.rmse.nn.wge(gold$Gold_Price, horizon=30, fit.mlp)
#Ensemble CODE - SHORT TERM 

ensemble  = (preds$fcst$y1[,1] + fore.mlp$mean)/2

#Plot
plot(seq(1,239,1), gold$Gold_Price, type = "l",xlim = c(0,250), ylab = "Gold Price", main = "30 Month Gold Price Forecast Ensemble", xlab='Month')
lines(seq(210,239,1), ensemble, type = "l", col = "red")

ASE = mean((gold$Gold_Price[210:239] - ensemble)^2)
ASE #22,925,936
## [1] 29599369
MULTIVARIATE (VAR, NN, ENSEMBLE) LONG TERM 30 MONTH FORECAST AHEAD
#Long term VAR

X =(cbind(gold$Gold_Price, gold$Crude_Oil,gold$Interest_Rate, gold$CPI, gold$USD_Index))

VARselect(X, lag.max=10, type='const', season=NULL, exogen=NULL)
## $selection
## AIC(n)  HQ(n)  SC(n) FPE(n) 
##      2      1      1      2 
## 
## $criteria
##                   1            2            3            4            5
## AIC(n) 2.252236e+01 2.238532e+01 2.240280e+01 2.252922e+01 2.252664e+01
## HQ(n)  2.270384e+01 2.271802e+01 2.288672e+01 2.316437e+01 2.331303e+01
## SC(n)  2.297220e+01 2.321001e+01 2.360235e+01 2.410363e+01 2.447592e+01
## FPE(n) 6.044561e+09 5.272064e+09 5.369151e+09 6.101494e+09 6.100020e+09
##                   6            7            8            9           10
## AIC(n) 2.254568e+01 2.262177e+01 2.249641e+01 2.260776e+01 2.266344e+01
## HQ(n)  2.348330e+01 2.371062e+01 2.373648e+01 2.399906e+01 2.420596e+01
## SC(n)  2.486982e+01 2.532077e+01 2.557026e+01 2.605648e+01 2.648702e+01
## FPE(n) 6.238744e+09 6.764269e+09 6.005345e+09 6.767855e+09 7.229206e+09
#Varselect picks p=2
lsfit=VAR(cbind(gold$Gold_Price, gold$Crude_Oil,gold$Interest_Rate, gold$CPI, gold30$USD_Index), p=2, type='const')
## Warning in cbind(gold$Gold_Price, gold$Crude_Oil, gold$Interest_Rate,
## gold$CPI, : number of rows of result is not a multiple of vector length (arg 5)
## Warning in VAR(cbind(gold$Gold_Price, gold$Crude_Oil, gold$Interest_Rate, : No column names supplied in y, using: y1, y2, y3, y4, y5 , instead.
preds=predict(lsfit, n.ahead=30)
preds
## $y1
##           fcst    lower     upper        CI
##  [1,] 54676.04 53275.47  56076.61  1400.571
##  [2,] 56311.34 54185.04  58437.64  2126.302
##  [3,] 57963.52 55263.66  60663.38  2699.859
##  [4,] 59617.10 56398.65  62835.54  3218.442
##  [5,] 61266.45 57554.91  64977.98  3711.533
##  [6,] 62909.49 58718.25  67100.73  4191.241
##  [7,] 64542.89 59878.40  69207.38  4664.491
##  [8,] 66162.56 61027.01  71298.12  5135.555
##  [9,] 67764.33 62157.30  73371.37  5607.034
## [10,] 69344.16 63263.73  75424.59  6080.427
## [11,] 70898.24 64341.76  77454.73  6556.487
## [12,] 72423.04 65387.60  79458.48  7035.440
## [13,] 73915.29 66398.15  81432.42  7517.137
## [14,] 75371.96 67370.80  83373.12  8001.160
## [15,] 76790.30 68303.41  85277.20  8486.896
## [16,] 78167.82 69194.22  87141.41  8973.593
## [17,] 79502.23 70041.83  88962.64  9460.405
## [18,] 80791.51 70845.09  90737.94  9946.424
## [19,] 82033.86 71603.16  92464.57 10430.703
## [20,] 83227.70 72315.42  94139.98 10912.280
## [21,] 84371.68 72981.48  95761.87 11390.194
## [22,] 85464.64 73601.15  97328.14 11863.494
## [23,] 86505.67 74174.42  98836.93 12331.255
## [24,] 87494.06 74701.48 100286.64 12792.581
## [25,] 88429.28 75182.67 101675.90 13246.616
## [26,] 89311.04 75618.49 103003.59 13692.549
## [27,] 90139.22 76009.61 104268.84 14129.617
## [28,] 90913.93 76356.82 105471.04 14557.110
## [29,] 91635.42 76661.05 106609.80 14974.375
## [30,] 92304.19 76923.37 107685.00 15380.816
## 
## $y2
##            fcst     lower     upper        CI
##  [1,]  3604.176  3068.803  4139.550  535.3735
##  [2,]  4088.108  3196.988  4979.228  891.1204
##  [3,]  4629.345  3482.292  5776.398 1147.0526
##  [4,]  5183.785  3857.494  6510.075 1326.2902
##  [5,]  5730.970  4279.114  7182.827 1451.8561
##  [6,]  6263.157  4721.671  7804.642 1541.4854
##  [7,]  6778.027  5170.017  8386.036 1608.0094
##  [8,]  7275.451  5614.894  8936.008 1660.5568
##  [9,]  7756.095  6050.495  9461.696 1705.6006
## [10,]  8220.816  6473.090  9968.541 1747.7254
## [11,]  8670.402  6880.245 10460.558 1790.1568
## [12,]  9105.484  7270.363 10940.606 1835.1214
## [13,]  9526.517  7642.421 11410.613 1884.0959
## [14,]  9933.784  7995.800 11871.769 1937.9849
## [15,] 10327.427  8330.170 12324.683 1997.2565
## [16,] 10707.464  8645.417 12769.511 2062.0469
## [17,] 11073.821  8941.575 13206.067 2132.2459
## [18,] 11426.347  9218.781 13633.912 2207.5652
## [19,] 11764.838  9477.244 14052.432 2287.5939
## [20,] 12089.053  9717.211 14460.894 2371.8417
## [21,] 12398.726  9938.954 14858.498 2459.7723
## [22,] 12693.583 10142.754 15244.411 2550.8283
## [23,] 12973.346 10328.897 15617.795 2644.4491
## [24,] 13237.749 10497.666 15977.833 2740.0836
## [25,] 13486.541 10649.342 16323.740 2837.1991
## [26,] 13719.492 10784.206 16654.779 2935.2862
## [27,] 13936.403 10902.540 16970.265 3033.8626
## [28,] 14137.104 11004.629 17269.578 3132.4746
## [29,] 14321.463 11090.764 17552.161 3230.6986
## [30,] 14489.386 11161.245 17817.526 3328.1406
## 
## $y3
##            fcst     lower     upper        CI
##  [1,]  4.256780  3.682452  4.831108 0.5743284
##  [2,]  4.374736  3.566847  5.182626 0.8078894
##  [3,]  4.528028  3.560310  5.495746 0.9677176
##  [4,]  4.705219  3.609470  5.800967 1.0957485
##  [5,]  4.906579  3.702450  6.110707 1.2041288
##  [6,]  5.130709  3.832911  6.428508 1.2977985
##  [7,]  5.375325  3.995752  6.754899 1.3795735
##  [8,]  5.638080  4.186768  7.089391 1.4513120
##  [9,]  5.916742  4.402363  7.431121 1.5143792
## [10,]  6.209227  4.639339  7.779114 1.5698875
## [11,]  6.513589  4.894769  8.132409 1.6188203
## [12,]  6.828019  5.165923  8.490114 1.6620957
## [13,]  7.150825  5.450227  8.851422 1.7005975
## [14,]  7.480421  5.745231  9.215612 1.7351904
## [15,]  7.815316  6.048591  9.582041 1.7667249
## [16,]  8.154098  6.358062  9.950134 1.7960362
## [17,]  8.495429  6.671490 10.319368 1.8239389
## [18,]  8.838036  6.986817 10.689255 1.8512193
## [19,]  9.180706  7.302080 11.059332 1.8786257
## [20,]  9.522281  7.615424 11.429138 1.9068573
## [21,]  9.861655  7.925101 11.798208 1.9365533
## [22,] 10.197768  8.229487 12.166050 1.9682816
## [23,] 10.529611  8.527082 12.532141 2.0025299
## [24,] 10.856219  8.816521 12.895916 2.0396975
## [25,] 11.176670  9.096580 13.256761 2.0800908
## [26,] 11.490090  9.366169 13.614012 2.1239212
## [27,] 11.795647  9.624341 13.966953 2.1713063
## [28,] 12.092554  9.870280 14.314828 2.2222740
## [29,] 12.380070 10.103301 14.656840 2.2767695
## [30,] 12.657498 10.322835 14.992162 2.3346635
## 
## $y4
##           fcst    lower    upper       CI
##  [1,] 130.1460 128.9989 131.2931 1.147108
##  [2,] 131.1422 129.3682 132.9162 1.773992
##  [3,] 132.2313 129.9750 134.4876 2.256315
##  [4,] 133.3933 130.7349 136.0518 2.658448
##  [5,] 134.6204 131.6107 137.6302 3.009742
##  [6,] 135.9082 132.5825 139.2340 3.325770
##  [7,] 137.2536 133.6376 140.8696 3.616010
##  [8,] 138.6540 134.7671 142.5408 3.886872
##  [9,] 140.1072 135.9641 144.2502 4.143064
## [10,] 141.6111 137.2229 145.9994 4.388269
## [11,] 143.1638 138.5383 147.7893 4.625522
## [12,] 144.7631 139.9057 149.6205 4.857426
## [13,] 146.4070 141.3207 151.4933 5.086274
## [14,] 148.0934 142.7793 153.4076 5.314129
## [15,] 149.8202 144.2773 155.3631 5.542868
## [16,] 151.5852 145.8110 157.3594 5.774206
## [17,] 153.3862 147.3765 159.3959 6.009711
## [18,] 155.2211 148.9703 161.4719 6.250804
## [19,] 157.0875 150.5887 163.5862 6.498763
## [20,] 158.9831 152.2284 165.7379 6.754724
## [21,] 160.9058 153.8862 167.9255 7.019672
## [22,] 162.8532 155.5588 170.1477 7.294446
## [23,] 164.8230 157.2433 172.4028 7.579736
## [24,] 166.8130 158.9369 174.6890 7.876086
## [25,] 168.8207 160.6368 177.0046 8.183898
## [26,] 170.8439 162.3405 179.3473 8.503434
## [27,] 172.8804 164.0456 181.7152 8.834828
## [28,] 174.9279 165.7498 184.1060 9.178092
## [29,] 176.9842 167.4511 186.5173 9.533127
## [30,] 179.0471 169.1474 188.9468 9.899728
## 
## $y5
##           fcst    lower     upper        CI
##  [1,] 96.70457 91.31693 102.09220  5.387632
##  [2,] 93.90284 86.32145 101.48423  7.581391
##  [3,] 91.01329 81.86805 100.15853  9.145244
##  [4,] 88.14500 77.75959  98.53042 10.385415
##  [5,] 85.32337 73.89725  96.74949 11.426119
##  [6,] 82.55837 70.22501  94.89172 12.333355
##  [7,] 79.85569 66.70784  93.00354 13.147853
##  [8,] 77.21902 63.32213  91.11592 13.896893
##  [9,] 74.65132 60.05162  89.25102 14.599698
## [10,] 72.15551 56.88524  87.42578 15.270267
## [11,] 69.73472 53.81573  85.65371 15.918992
## [12,] 67.39235 50.83871  83.94599 16.553637
## [13,] 65.13200 47.95203  82.31198 17.179975
## [14,] 62.95744 45.15523  80.75966 17.802216
## [15,] 60.87252 42.44921  79.29584 18.423316
## [16,] 58.88109 39.83587  77.92631 19.045216
## [17,] 56.98695 37.31793  76.65597 19.669022
## [18,] 55.19380 34.89864  75.48896 20.295157
## [19,] 53.50517 32.58168  74.42866 20.923489
## [20,] 51.92440 30.37097  73.47784 21.553436
## [21,] 50.45458 28.27052  72.63864 22.184060
## [22,] 49.09855 26.28440  71.91270 22.814147
## [23,] 47.85884 24.41656  71.30111 23.442275
## [24,] 46.73767 22.67079  70.80454 24.066874
## [25,] 45.73694 21.05066  70.42322 24.686278
## [26,] 44.85820 19.55943  70.15696 25.298769
## [27,] 44.10263 18.20002  70.00524 25.902613
## [28,] 43.47107 16.97497  69.96716 26.496094
## [29,] 42.96397 15.88643  70.04151 27.077541
## [30,] 42.58142 14.93607  70.22677 27.645350
preds$fcst$y1[1:30,1]
##  [1] 54676.04 56311.34 57963.52 59617.10 61266.45 62909.49 64542.89 66162.56
##  [9] 67764.33 69344.16 70898.24 72423.04 73915.29 75371.96 76790.30 78167.82
## [17] 79502.23 80791.51 82033.86 83227.70 84371.68 85464.64 86505.67 87494.06
## [25] 88429.28 89311.04 90139.22 90913.93 91635.42 92304.19
plot(seq(1,239,1), gold$Gold_Price, type='l', ylim=c(0,100000), xlim=c(0,270) ) 
points(seq(240,269,1),preds$fcst$y1[1:30,1], type='l', col='red', pch=15)

fanchart(preds)

fanchart(preds, names='y1')

# Long TERM ahead forecasts - MULTIVARIATE NEURAL NET
#gold30 is the gold data from 1-209, leaving out 210-239

#forecast crude oil, interest rate, cpi, and usd index

#crude
fit.mlp.crude = mlp(ts(gold$Crude_Oil),reps = 20, comb = "median")
plot(fit.mlp.crude)

fore.mlp.crude = forecast(fit.mlp.crude, h = 30)
plot(fore.mlp.crude)

#interest
fit.mlp.int = mlp(ts(gold$Interest_Rate),reps = 20, comb = "median")
fore.mlp.int = forecast(fit.mlp.int, h = 30)
plot(fore.mlp.int)

#CPI
fit.mlp.cpi = mlp(ts(gold$CPI),reps = 20, comb = "median")
plot(fit.mlp.cpi)

fore.mlp.cpi = forecast(fit.mlp.cpi, h = 30)
plot(fore.mlp.cpi)

#USD
fit.mlp.usd = mlp(ts(gold$USD_Index),reps = 20, comb = "median")
fore.mlp.usd = forecast(fit.mlp.usd, h = 30)
plot(fore.mlp.usd)

#package them up in data frame.
#fore.mlp.temp1 = dplyr::lag(as.vector(fore.mlp.temp$mean),1)
GDF_fore = data.frame(Month = ts(seq(1,269,1)),crude_oil = ts(c(gold$Crude_Oil,fore.mlp.crude$mean)), interest_rate = ts(c(gold$Interest_Rate,fore.mlp.int$mean)), CPI = ts(c(gold$CPI,fore.mlp.cpi$mean)), USD_index = ts(c(gold$USD_Index,fore.mlp.usd$mean)))
GDF_fore
##     Month crude_oil interest_rate      CPI USD_index
## 1       1  1455.510      8.000000  37.2300 116.65000
## 2       2  1512.470      8.000000  37.3100 115.24000
## 3       3  1178.110      8.000000  36.9800 109.56000
## 4       4  1208.180      8.000000  36.9000 110.52000
## 5       5  1267.180      7.500000  36.7300 112.01000
## 6       6  1166.450      7.000000  36.9000 117.37000
## 7       7  1203.330      7.000000  37.1500 115.85000
## 8       8  1292.570      7.000000  37.4000 119.07000
## 9       9  1267.730      7.000000  37.8900 119.43000
## 10     10  1169.120      7.000000  38.3900 117.18000
## 11     11  1216.800      7.000000  38.6400 113.42000
## 12     12  1201.160      7.000000  38.5600 113.48000
## 13     13   995.460      6.500000  38.8000 114.86000
## 14     14   897.070      6.500000  39.1400 116.13000
## 15     15   887.420      6.500000  38.8900 116.75000
## 16     16   925.630      6.500000  38.7200 120.24000
## 17     17   972.860      6.500000  38.6400 119.16000
## 18     18  1152.200      6.500000  38.8000 118.62000
## 19     19  1244.020      6.500000  38.8900 115.19000
## 20     20  1257.830      6.500000  39.1400 111.81000
## 21     21  1199.060      6.500000  39.4700 106.11000
## 22     22  1255.670      6.500000  39.8800 107.41000
## 23     23  1301.250      6.500000  40.1300 106.98000
## 24     24  1369.920      6.500000  40.2100 106.87000
## 25     25  1331.610      6.500000  40.3800 106.64000
## 26     26  1184.180      6.250000  40.5500 106.41000
## 27     27  1342.560      6.250000  40.1300 101.85000
## 28     28  1473.850      6.250000  40.0500  99.91000
## 29     29  1569.550      6.250000  40.1300  99.71000
## 30     30  1446.380      6.250000  40.3800  99.06000
## 31     31  1210.970      6.250000  40.8800  97.19000
## 32     32  1226.990      6.000000  40.9600  93.27000
## 33     33  1304.450      6.000000  41.2100  94.73000
## 34     34  1321.850      6.000000  41.5400  96.89000
## 35     35  1363.370      6.000000  41.3800  98.10000
## 36     36  1232.460      6.000000  41.3800  92.85000
## 37     37  1316.780      6.000000  41.7100  92.73000
## 38     38  1325.540      6.000000  41.7900  90.21000
## 39     39  1366.360      6.000000  41.6200  86.92000
## 40     40  1425.740      6.000000  41.7900  87.20000
## 41     41  1418.360      6.000000  41.7900  87.31000
## 42     42  1515.650      6.000000  41.7900  87.61000
## 43     43  1480.990      6.000000  41.7900  90.48000
## 44     44  1699.290      6.000000  42.1200  88.95000
## 45     45  1617.640      6.000000  42.4500  88.80000
## 46     46  1744.590      6.000000  42.8700  89.96000
## 47     47  1950.090      6.000000  43.2800  88.94000
## 48     48  1917.680      6.000000  43.3700  87.36000
## 49     49  2146.340      6.000000  43.6100  84.91000
## 50     50  1900.580      6.000000  43.5300  81.82000
## 51     51  1717.000      6.000000  43.2000  80.85000
## 52     52  1880.230      6.000000  43.6100  83.60000
## 53     53  1957.600      6.000000  43.5300  82.51000
## 54     54  2225.570      6.000000  43.5300  84.06000
## 55     55  2215.050      6.000000  43.8600  84.43000
## 56     56  2080.200      6.000000  43.7000  87.76000
## 57     57  2348.850      6.000000  43.8600  89.11000
## 58     58  2454.200      6.000000  44.6100  89.35000
## 59     59  2700.010      6.000000  44.7700  87.58000
## 60     60  2709.210      6.000000  44.9400  89.52000
## 61     61  2608.220      6.000000  45.4400  90.07000
## 62     62  2516.770      6.000000  45.8500  91.57000
## 63     63  2576.490      6.000000  45.6000  91.17000
## 64     64  2773.130      6.000000  45.5200  88.96000
## 65     65  2646.560      6.000000  45.5200  90.11000
## 66     66  2709.890      6.000000  45.5200  89.73000
## 67     67  3055.210      6.000000  45.9000  86.11000
## 68     68  3118.700      6.000000  46.2900  84.72000
## 69     69  3145.130      6.000000  47.0500  85.22000
## 70     70  3365.750      6.000000  47.4300  85.30000
## 71     71  3341.970      6.000000  47.4300  85.05000
## 72     72  2865.030      6.000000  47.8200  85.97000
## 73     73  2633.080      6.000000  48.5800  85.32000
## 74     74  2607.990      6.000000  48.5800  82.92000
## 75     75  2722.260      6.000000  48.5800  83.72000
## 76     76  2373.050      6.000000  48.5800  84.61000
## 77     77  2541.990      6.000000  48.9600  83.57000
## 78     78  2667.950      6.000000  48.5800  82.93000
## 79     79  2742.350      6.000000  48.9600  81.45000
## 80     80  2658.010      6.000000  49.3500  82.30000
## 81     81  2779.560      6.000000  49.7300  81.92000
## 82     82  2974.640      6.000000  50.4900  80.77000
## 83     83  2862.540      6.000000  50.8800  80.79000
## 84     84  3096.500      6.000000  50.8800  77.72000
## 85     85  3238.900      6.000000  51.2600  76.48000
## 86     86  3602.450      6.000000  51.2600  76.15000
## 87     87  3530.670      6.000000  51.2600  76.69000
## 88     88  3570.710      6.000000  51.2600  75.18000
## 89     89  3710.340      6.000000  51.6400  73.71000
## 90     90  4109.920      6.000000  52.4100  71.80000
## 91     91  4353.720      6.000000  52.7900  72.51000
## 92     92  5165.850      6.000000  53.1700  72.88000
## 93     93  5631.690      6.000000  53.5500  72.46000
## 94     94  5689.980      6.000000  54.7000  73.23000
## 95     95  4919.520      6.000000  55.4700  77.38000
## 96     96  4540.910      6.000000  55.8500  79.45000
## 97     97  3535.800      6.000000  56.6100  85.63000
## 98     98  2644.710      6.000000  56.6100  86.52000
## 99     99  2010.860      6.000000  56.2300  81.15000
## 100   100  2142.120      6.000000  56.6100  85.83000
## 101   101  2059.460      6.000000  56.6100  88.17000
## 102   102  2391.750      6.000000  56.6100  85.51000
## 103   103  2517.580      6.000000  57.3800  84.82000
## 104   104  2822.250      6.000000  57.7600  79.23000
## 105   105  3303.550      6.000000  58.5300  80.16000
## 106   106  3137.000      6.000000  61.2000  78.35000
## 107   107  3461.090      6.000000  61.9700  78.17000
## 108   108  3310.800      6.000000  62.3500  76.65000
## 109   109  3461.100      6.000000  63.1200  76.30000
## 110   110  3611.430      6.000000  64.2700  74.78000
## 111   111  3491.650      6.000000  64.6500  77.86000
## 112   112  3541.880      6.000000  65.8000  79.46000
## 113   113  3463.320      6.000000  65.0300  80.36000
## 114   114  3607.990      6.000000  65.0300  81.07000
## 115   115  3745.920      6.000000  65.0300  81.87000
## 116   116  3461.170      6.000000  65.8000  86.59000
## 117   117  3479.770      6.000000  66.5600  86.02000
## 118   118  3495.720      6.000000  68.0900  81.54000
## 119   119  3531.140      6.000000  68.0900  83.20000
## 120   120  3504.320      6.000000  68.4700  78.72000
## 121   121  3629.800      6.000000  69.2400  77.27000
## 122   122  3793.460      6.000000  69.6200  81.19000
## 123   123  4065.660      6.000000  70.7700  79.03000
## 124   124  4206.660      6.000000  71.9200  77.73000
## 125   125  4450.500      6.000000  70.7700  76.89000
## 126   126  4888.110      6.000000  70.7700  75.86000
## 127   127  5159.400      6.000000  71.1500  72.93000
## 128   128  4851.800      6.000000  71.5300  74.64000
## 129   129  4747.570      6.000000  72.3000  74.30000
## 130   130  4793.300      6.000000  73.8300  73.90000
## 131   131  4550.040      6.000000  74.2100  74.12000
## 132   132  4811.930      6.000000  75.3600  78.55000
## 133   133  4916.610      6.000000  75.7400  76.17000
## 134   134  5343.290      6.000000  76.1200  78.38000
## 135   135  5486.720      6.000000  75.3600  80.18000
## 136   136  5484.920      6.000000  75.7400  79.29000
## 137   137  5540.260      9.500000  76.1200  78.74000
## 138   138  5927.550      9.500000  76.8900  79.00000
## 139   139  5888.490      9.000000  78.4200  78.78000
## 140   140  5655.940      9.000000  78.8000  83.04000
## 141   141  5083.600      9.000000  79.5700  81.63000
## 142   142  5372.190      9.000000  81.1000  82.64000
## 143   143  5848.750      9.000000  81.8600  81.21000
## 144   144  5798.480      9.000000  82.2400  79.94000
## 145   145  5476.430      9.000000  83.0100  79.92000
## 146   146  5536.010      9.000000  83.3900  80.15000
## 147   147  5526.620      9.000000  83.7700  79.77000
## 148   148  5708.320      9.000000  84.5400  79.21000
## 149   149  5784.940      8.750000  85.3000  81.95000
## 150   150  5575.840      8.500000  85.6900  83.22000
## 151   151  5375.040      8.500000  86.4500  81.75000
## 152   152  5468.660      8.250000  87.2200  83.26000
## 153   153  5817.690      8.250000  88.3600  83.14000
## 154   154  6292.380     10.250000  89.8900  81.45000
## 155   155  6836.670     10.250000  90.6600  82.09000
## 156   156  6926.830      9.500000  91.0400  80.22000
## 157   157  6497.770      8.750000  92.1900  80.19000
## 158   158  6435.780      8.750000  92.9600  80.68000
## 159   159  6534.280      8.750000  91.4200  80.03000
## 160   160  6344.000      9.000000  90.6600  81.31000
## 161   161  6529.280      9.000000  91.0400  79.69000
## 162   162  6343.000      9.000000  91.4200  80.10000
## 163   163  6329.600      9.000000  92.5700  79.47000
## 164   164  6273.130      9.000000  93.3400  80.37000
## 165   165  6471.050      9.000000  94.1000  79.78000
## 166   166  6320.510      9.000000  96.4000  81.46000
## 167   167  6092.560      9.000000  96.7800  82.75000
## 168   168  5835.690      9.000000  96.7800  85.94000
## 169   169  5280.840      9.000000  96.7800  86.92000
## 170   170  4748.530      9.000000  96.7800  88.36000
## 171   171  3806.550      9.000000  96.7800  90.27000
## 172   172  2927.200      8.750000  97.1600  94.80000
## 173   173  3398.510      8.750000  96.7800  95.32000
## 174   174  3299.230      8.500000  97.1600  98.36000
## 175   175  3611.030      8.500000  97.9300  94.60000
## 176   176  3988.780      8.500000  98.6900  96.91000
## 177   177  3915.300      8.250000  99.8400  95.48000
## 178   178  3458.510      8.250000 100.6100  97.34000
## 179   179  2973.160      8.250000 100.9900  95.82000
## 180   180  3064.430      8.250000 101.7500  96.35000
## 181   181  3055.950      7.750000 102.9000  96.95000
## 182   182  2847.430      7.750000 103.2800 100.17000
## 183   183  2435.400      7.750000 102.9000  98.63000
## 184   184  2004.000      7.750000 102.9000  99.61000
## 185   185  2117.580      7.750000 102.1400  98.21000
## 186   186  2503.950      7.750000 102.5200  94.59000
## 187   187  2708.630      7.000000 103.6700  93.08000
## 188   188  3072.750      7.000000 105.2000  95.89000
## 189   189  3208.660      7.000000 105.9600  96.14000
## 190   190  2966.280      7.000000 107.1100  95.53000
## 191   191  3004.160      7.000000 106.3400  96.02000
## 192   192  3006.050      7.000000 105.9600  95.46000
## 193   193  3290.460      6.750000 106.3400  98.44000
## 194   194  3056.290      6.750000 105.9600 101.50000
## 195   195  3572.840      6.750000 105.2000 102.21000
## 196   196  3649.890      6.750000 104.8100  99.51000
## 197   197  3647.030      6.750000 104.8100 101.12000
## 198   198  3355.090      6.750000 105.2000 100.35000
## 199   199  3365.040      6.500000 105.9600  99.05000
## 200   200  3213.830      6.500000 106.3400  96.92000
## 201   201  2975.010      6.500000 107.1100  95.63000
## 202   202  3071.230      6.500000 109.0200  92.86000
## 203   203  3194.460      6.250000 109.0200  92.67000
## 204   204  3413.190      6.250000 109.0200  93.08000
## 205   205  3574.530      6.250000 109.7900  94.55000
## 206   206  3887.810      6.250000 110.1700  93.05000
## 207   207  3930.990      6.250000 109.4000  92.12000
## 208   208  4215.160      6.250000 110.1700  89.13000
## 209   209  4085.160      6.250000 109.7900  90.61000
## 210   210  4171.720      6.250000 109.7900  89.97000
## 211   211  4516.930      6.250000 110.1700  91.84000
## 212   212  4959.750      6.250000 110.5500  93.98000
## 213   213  4879.750      6.500000 111.3200  94.64000
## 214   214  4992.510      6.500000 115.1400  94.49000
## 215   215  4942.530      6.750000 115.1400  95.14000
## 216   216  5448.550      6.750000 115.1400  95.13000
## 217   217  5648.690      6.750000 115.5200  97.13000
## 218   218  4476.090      6.750000 115.5200  97.27000
## 219   219  3822.070      6.750000 115.1400  96.17000
## 220   220  4003.080      6.750000 117.4400  95.58000
## 221   221  4352.940      6.500000 117.4400  96.16000
## 222   222  4432.040      6.500000 118.2000  97.28000
## 223   223  4761.330      6.250000 119.3500  97.48000
## 224   224  4664.020      6.250000 120.1100  97.75000
## 225   225  4149.670      6.000000 120.8800  96.13000
## 226   226  4230.220      6.000000 122.0300  98.52000
## 227   227  4102.970      5.650000 122.4100  98.92000
## 228   228  4282.870      5.650000 123.1800  99.38000
## 229   229  4069.140      5.400000 124.3200  97.35000
## 230   230  4314.320      5.400000 125.4700  98.27000
## 231   231  4509.770      5.400000 126.2400  96.39000
## 232   232  4395.910      5.400000 126.2400  97.39000
## 233   233  3811.780      5.400000 125.4700  98.13000
## 234   234  2392.980      4.650000 124.7100  99.05000
## 235   235  1603.020      4.650000 125.8500  99.57000
## 236   236  2298.550      4.250000 126.2400  98.34000
## 237   237  2987.460      4.250000 127.0000  97.39000
## 238   238  3156.010      4.250000 128.5300  93.35000
## 239   239  3243.750      4.250000 129.3000  92.14000
## 240   240  3109.723      4.321809 130.1653  91.53395
## 241   241  3070.150      4.394225 131.0459  91.15024
## 242   242  3089.778      4.462599 131.5239  90.78024
## 243   243  3131.685      4.525546 131.9760  90.39833
## 244   244  3182.010      4.586388 132.4019  90.03844
## 245   245  3234.894      4.643076 132.7427  89.68504
## 246   246  3285.429      4.695248 133.0394  89.32964
## 247   247  3328.113      4.743424 133.3321  89.00371
## 248   248  3366.020      4.788229 133.4585  88.70215
## 249   249  3397.124      4.826525 133.6046  88.36888
## 250   250  3426.208      4.860907 133.8431  88.03321
## 251   251  3463.962      4.892695 133.9395  87.70108
## 252   252  3495.121      4.922248 134.1336  87.37346
## 253   253  3532.722      4.949861 134.3458  87.05350
## 254   254  3582.445      4.975778 134.4742  86.75149
## 255   255  3630.585      5.000206 134.6346  86.45667
## 256   256  3670.369      5.023318 134.7807  86.16972
## 257   257  3710.163      5.045259 134.9295  85.89125
## 258   258  3749.957      5.066156 135.0772  85.62180
## 259   259  3789.748      5.086115 135.2371  85.36183
## 260   260  3829.537      5.105229 135.4269  85.11169
## 261   261  3869.326      5.123579 135.6494  84.87169
## 262   262  3909.115      5.141236 135.8655  84.64200
## 263   263  3947.280      5.158420 136.0712  84.42277
## 264   264  3984.509      5.176235 136.2543  84.21403
## 265   265  4025.708      5.193497 136.4180  84.02752
## 266   266  4069.717      5.210248 136.5736  83.86173
## 267   267  4113.727      5.226526 136.7931  83.70573
## 268   268  4157.737      5.242366 137.0049  83.55919
## 269   269  4201.746      5.257797 137.1314  83.42177
#forecast cmort using mlp with forecasted xreg (don't need to forecast week.)
goldDF = data.frame(Date = ts(seq(1,239,1)),crude_oil = ts(gold$Crude_Oil), interest_rate = ts(gold$Interest_Rate), CPI = ts(gold$CPI),  USD_index = ts(gold$USD_Index))
fit.mlp = mlp(ts(gold$Gold_Price),reps = 20,comb = "mean",xreg = goldDF)
fit.mlp #176623.0505
## MLP fit with 5 hidden nodes and 20 repetitions.
## Series modelled in differences: D1.
## Univariate lags: (1)
## 5 regressors included.
## - Regressor 1 lags: (1)
## - Regressor 2 lags: (1,4)
## - Regressor 3 lags: (3)
## - Regressor 4 lags: (1)
## - Regressor 5 lags: (1,3)
## Forecast combined using the mean operator.
## MSE: 175046.8659.
plot(fit.mlp)

fore.mlp = forecast(fit.mlp, h = 30, xreg = GDF_fore)
plot(fore.mlp)

#Plot
plot(seq(1,239,1), gold$Gold_Price, type = "l",xlim = c(0,270), ylim = c(0, 150000), ylab = "Gold Price", main = "30 Month Gold Price Forecast")
lines(seq(240,269,1), fore.mlp$mean, type = "l", col = "red")

fore.mlp
##     Point Forecast
## 240       55184.43
## 241       57539.75
## 242       59592.05
## 243       61938.74
## 244       63874.82
## 245       66361.75
## 246       68301.55
## 247       70654.75
## 248       72632.21
## 249       74877.53
## 250       76939.28
## 251       79177.64
## 252       81085.22
## 253       83280.56
## 254       85257.58
## 255       87419.84
## 256       89305.05
## 257       91433.88
## 258       93247.22
## 259       95360.49
## 260       97051.67
## 261       99055.29
## 262      100756.41
## 263      102651.34
## 264      104301.29
## 265      106223.12
## 266      107858.25
## 267      109818.53
## 268      111448.40
## 269      113391.26
#Ensemble CODE

ensemble  = (preds$fcst$y1[,1] + fore.mlp$mean)/2

#Plot
plot(seq(1,239,1), gold$Gold_Price, type = "l",xlim = c(0,270), ylab = "Gold Price", main = "30 Month Gold Price Forecast", ylim=c(0,150000))
lines(seq(240,269,1), ensemble, type = "l", col = "red")

MULTIVARIATE (VAR, NN, ENSEMBLE) SHORT TERM (NOT AHEAD - FORECASTING LAST 10 MONTHS)
#short term -- VAR
gold10 = gold[1:229,]

X =(cbind(gold10$Gold_Price, gold10$Crude_Oil,gold10$Interest_Rate, gold10$CPI, gold10$USD_Index))

VARselect(X, lag.max=10, type='const', season=NULL, exogen=NULL)
## $selection
## AIC(n)  HQ(n)  SC(n) FPE(n) 
##      2      1      1      2 
## 
## $criteria
##                   1            2            3            4            5
## AIC(n) 2.226254e+01 2.217108e+01 2.217302e+01 2.229633e+01 2.229639e+01
## HQ(n)  2.245004e+01 2.251482e+01 2.267302e+01 2.295258e+01 2.310889e+01
## SC(n)  2.272680e+01 2.302221e+01 2.341103e+01 2.392123e+01 2.430817e+01
## FPE(n) 4.661540e+09 4.255589e+09 4.267614e+09 4.835679e+09 4.848897e+09
##                   6            7            8            9           10
## AIC(n) 2.230290e+01 2.239728e+01 2.226241e+01 2.236660e+01 2.240591e+01
## HQ(n)  2.327165e+01 2.352227e+01 2.354366e+01 2.380410e+01 2.399965e+01
## SC(n)  2.470156e+01 2.518281e+01 2.543483e+01 2.592590e+01 2.635208e+01
## FPE(n) 4.899859e+09 5.414392e+09 4.765922e+09 5.339172e+09 5.619047e+09
#Varselect picks p=2
lsfit=VAR(X, p=2, type='const')
## Warning in VAR(X, p = 2, type = "const"): No column names supplied in y, using: y1, y2, y3, y4, y5 , instead.
preds=predict(lsfit, n.ahead=10)
preds
## $y1
##           fcst    lower    upper       CI
##  [1,] 38581.70 37251.87 39911.53 1329.829
##  [2,] 39017.90 37029.19 41006.62 1988.718
##  [3,] 39432.66 36975.49 41889.84 2457.176
##  [4,] 39825.90 36987.84 42663.97 2838.066
##  [5,] 40206.40 37037.87 43374.94 3168.532
##  [6,] 40577.17 37113.60 44040.74 3463.572
##  [7,] 40938.44 37207.02 44669.87 3731.427
##  [8,] 41289.95 37312.49 45267.40 3977.453
##  [9,] 41631.46 37426.13 45836.78 4205.321
## [10,] 41962.91 37545.28 46380.54 4417.630
## 
## $y2
##           fcst    lower    upper        CI
##  [1,] 4120.738 3633.643 4607.834  487.0953
##  [2,] 4302.538 3516.336 5088.740  786.2021
##  [3,] 4515.013 3527.637 5502.388  987.3755
##  [4,] 4718.700 3596.169 5841.230 1122.5305
##  [5,] 4901.719 3683.207 6120.231 1218.5120
##  [6,] 5061.906 3769.189 6354.623 1292.7168
##  [7,] 5200.492 3845.135 6555.849 1355.3572
##  [8,] 5319.821 3907.780 6731.862 1412.0410
##  [9,] 5422.412 3956.809 6888.016 1465.6039
## [10,] 5510.599 3993.298 7027.900 1517.3012
## 
## $y3
##           fcst    lower    upper        CI
##  [1,] 5.611490 5.040847 6.182134 0.5706436
##  [2,] 5.788488 4.998243 6.578732 0.7902443
##  [3,] 5.942549 5.017551 6.867548 0.9249985
##  [4,] 6.089533 5.065845 7.113222 1.0236885
##  [5,] 6.233347 5.130497 7.336198 1.1028502
##  [6,] 6.373728 5.204516 7.542940 1.1692119
##  [7,] 6.509815 5.283244 7.736385 1.2265708
##  [8,] 6.640815 5.363375 7.918255 1.2774400
##  [9,] 6.766087 5.442521 8.089654 1.3235668
## [10,] 6.885161 5.518966 8.251356 1.3661952
## 
## $y4
##           fcst    lower    upper       CI
##  [1,] 125.0660 123.9300 126.2021 1.136065
##  [2,] 125.7371 123.9938 127.4804 1.743293
##  [3,] 126.4215 124.2143 128.6287 2.207188
##  [4,] 127.1215 124.5284 129.7146 2.593088
##  [5,] 127.8336 124.9029 130.7644 2.930722
##  [6,] 128.5551 125.3194 131.7908 3.235676
##  [7,] 129.2839 125.7668 132.8010 3.517129
##  [8,] 130.0187 126.2377 133.7997 3.781006
##  [9,] 130.7585 126.7271 134.7899 4.031393
## [10,] 131.5024 127.2311 135.7736 4.271237
## 
## $y5
##           fcst    lower    upper        CI
##  [1,] 96.85482 92.84737 100.8623  4.007447
##  [2,] 96.08543 90.44229 101.7286  5.643142
##  [3,] 95.36284 88.54609 102.1796  6.816752
##  [4,] 94.71050 86.95852 102.4625  7.751984
##  [5,] 94.13677 85.59516 102.6784  8.541616
##  [6,] 93.64314 84.41226 102.8740  9.230881
##  [7,] 93.22579 83.38012 103.0714  9.845664
##  [8,] 92.87864 82.47658 103.2807 10.402060
##  [9,] 92.59528 81.68473 103.5058 10.910548
## [10,] 92.36957 80.99133 103.7478 11.378246
preds$fcst$y1[1:10,1]
##  [1] 38581.70 39017.90 39432.66 39825.90 40206.40 40577.17 40938.44 41289.95
##  [9] 41631.46 41962.91
plot(seq(1,239,1), gold$Gold_Price, type='l', xlab='Months', ylab='Gold Price', main='10 Month Gold Price Forecast' ) #ylim=c(0,6)
points(seq(230,239,1),preds$fcst$y1[1:10,1], type='l', col='red', pch=15)

fanchart(preds)

fanchart(preds, names='y1')

ASE = mean((preds$fcst$y1[1:10,1]-gold$Gold_Price[230:239])^2)
ASE #28,534,936
## [1] 28534936
#roll.win.rmse.wge(gold$Gold_Price, horizon=10, preds)
#short term
#gold10 is the gold data from 1-229, leaving out 230-239

#forecast crude oil, interest rate, cpi, and usd index

#crude
fit.mlp.crude = mlp(ts(gold10$Crude_Oil),reps = 20, comb = "mean")
plot(fit.mlp.crude)

fore.mlp.crude = forecast(fit.mlp.crude, h = 10)
plot(fore.mlp.crude)

#interest
fit.mlp.int = mlp(ts(gold10$Interest_Rate),reps = 20, comb = "mean")
fore.mlp.int = forecast(fit.mlp.int, h = 10)
plot(fore.mlp.int)

#CPI
fit.mlp.cpi = mlp(ts(gold10$CPI),reps = 20, comb = "mean")
plot(fit.mlp.cpi)

fore.mlp.cpi = forecast(fit.mlp.cpi, h = 10)
plot(fore.mlp.cpi)

#USD
fit.mlp.usd = mlp(ts(gold10$USD_Index),reps = 20, comb = "mean")
fore.mlp.usd = forecast(fit.mlp.usd, h = 10)
plot(fore.mlp.usd)

#package them up in data frame.
#fore.mlp.temp1 = dplyr::lag(as.vector(fore.mlp.temp$mean),1)
GDF_fore = data.frame(Month = ts(seq(1,239,1)),crude_oil = ts(c(gold10$Crude_Oil,fore.mlp.crude$mean)), interest_rate = ts(c(gold10$Interest_Rate,fore.mlp.int$mean)), CPI = ts(c(gold10$CPI,fore.mlp.cpi$mean)), USD_index = ts(c(gold10$USD_Index,fore.mlp.usd$mean)))
GDF_fore
##     Month crude_oil interest_rate      CPI USD_index
## 1       1  1455.510      8.000000  37.2300 116.65000
## 2       2  1512.470      8.000000  37.3100 115.24000
## 3       3  1178.110      8.000000  36.9800 109.56000
## 4       4  1208.180      8.000000  36.9000 110.52000
## 5       5  1267.180      7.500000  36.7300 112.01000
## 6       6  1166.450      7.000000  36.9000 117.37000
## 7       7  1203.330      7.000000  37.1500 115.85000
## 8       8  1292.570      7.000000  37.4000 119.07000
## 9       9  1267.730      7.000000  37.8900 119.43000
## 10     10  1169.120      7.000000  38.3900 117.18000
## 11     11  1216.800      7.000000  38.6400 113.42000
## 12     12  1201.160      7.000000  38.5600 113.48000
## 13     13   995.460      6.500000  38.8000 114.86000
## 14     14   897.070      6.500000  39.1400 116.13000
## 15     15   887.420      6.500000  38.8900 116.75000
## 16     16   925.630      6.500000  38.7200 120.24000
## 17     17   972.860      6.500000  38.6400 119.16000
## 18     18  1152.200      6.500000  38.8000 118.62000
## 19     19  1244.020      6.500000  38.8900 115.19000
## 20     20  1257.830      6.500000  39.1400 111.81000
## 21     21  1199.060      6.500000  39.4700 106.11000
## 22     22  1255.670      6.500000  39.8800 107.41000
## 23     23  1301.250      6.500000  40.1300 106.98000
## 24     24  1369.920      6.500000  40.2100 106.87000
## 25     25  1331.610      6.500000  40.3800 106.64000
## 26     26  1184.180      6.250000  40.5500 106.41000
## 27     27  1342.560      6.250000  40.1300 101.85000
## 28     28  1473.850      6.250000  40.0500  99.91000
## 29     29  1569.550      6.250000  40.1300  99.71000
## 30     30  1446.380      6.250000  40.3800  99.06000
## 31     31  1210.970      6.250000  40.8800  97.19000
## 32     32  1226.990      6.000000  40.9600  93.27000
## 33     33  1304.450      6.000000  41.2100  94.73000
## 34     34  1321.850      6.000000  41.5400  96.89000
## 35     35  1363.370      6.000000  41.3800  98.10000
## 36     36  1232.460      6.000000  41.3800  92.85000
## 37     37  1316.780      6.000000  41.7100  92.73000
## 38     38  1325.540      6.000000  41.7900  90.21000
## 39     39  1366.360      6.000000  41.6200  86.92000
## 40     40  1425.740      6.000000  41.7900  87.20000
## 41     41  1418.360      6.000000  41.7900  87.31000
## 42     42  1515.650      6.000000  41.7900  87.61000
## 43     43  1480.990      6.000000  41.7900  90.48000
## 44     44  1699.290      6.000000  42.1200  88.95000
## 45     45  1617.640      6.000000  42.4500  88.80000
## 46     46  1744.590      6.000000  42.8700  89.96000
## 47     47  1950.090      6.000000  43.2800  88.94000
## 48     48  1917.680      6.000000  43.3700  87.36000
## 49     49  2146.340      6.000000  43.6100  84.91000
## 50     50  1900.580      6.000000  43.5300  81.82000
## 51     51  1717.000      6.000000  43.2000  80.85000
## 52     52  1880.230      6.000000  43.6100  83.60000
## 53     53  1957.600      6.000000  43.5300  82.51000
## 54     54  2225.570      6.000000  43.5300  84.06000
## 55     55  2215.050      6.000000  43.8600  84.43000
## 56     56  2080.200      6.000000  43.7000  87.76000
## 57     57  2348.850      6.000000  43.8600  89.11000
## 58     58  2454.200      6.000000  44.6100  89.35000
## 59     59  2700.010      6.000000  44.7700  87.58000
## 60     60  2709.210      6.000000  44.9400  89.52000
## 61     61  2608.220      6.000000  45.4400  90.07000
## 62     62  2516.770      6.000000  45.8500  91.57000
## 63     63  2576.490      6.000000  45.6000  91.17000
## 64     64  2773.130      6.000000  45.5200  88.96000
## 65     65  2646.560      6.000000  45.5200  90.11000
## 66     66  2709.890      6.000000  45.5200  89.73000
## 67     67  3055.210      6.000000  45.9000  86.11000
## 68     68  3118.700      6.000000  46.2900  84.72000
## 69     69  3145.130      6.000000  47.0500  85.22000
## 70     70  3365.750      6.000000  47.4300  85.30000
## 71     71  3341.970      6.000000  47.4300  85.05000
## 72     72  2865.030      6.000000  47.8200  85.97000
## 73     73  2633.080      6.000000  48.5800  85.32000
## 74     74  2607.990      6.000000  48.5800  82.92000
## 75     75  2722.260      6.000000  48.5800  83.72000
## 76     76  2373.050      6.000000  48.5800  84.61000
## 77     77  2541.990      6.000000  48.9600  83.57000
## 78     78  2667.950      6.000000  48.5800  82.93000
## 79     79  2742.350      6.000000  48.9600  81.45000
## 80     80  2658.010      6.000000  49.3500  82.30000
## 81     81  2779.560      6.000000  49.7300  81.92000
## 82     82  2974.640      6.000000  50.4900  80.77000
## 83     83  2862.540      6.000000  50.8800  80.79000
## 84     84  3096.500      6.000000  50.8800  77.72000
## 85     85  3238.900      6.000000  51.2600  76.48000
## 86     86  3602.450      6.000000  51.2600  76.15000
## 87     87  3530.670      6.000000  51.2600  76.69000
## 88     88  3570.710      6.000000  51.2600  75.18000
## 89     89  3710.340      6.000000  51.6400  73.71000
## 90     90  4109.920      6.000000  52.4100  71.80000
## 91     91  4353.720      6.000000  52.7900  72.51000
## 92     92  5165.850      6.000000  53.1700  72.88000
## 93     93  5631.690      6.000000  53.5500  72.46000
## 94     94  5689.980      6.000000  54.7000  73.23000
## 95     95  4919.520      6.000000  55.4700  77.38000
## 96     96  4540.910      6.000000  55.8500  79.45000
## 97     97  3535.800      6.000000  56.6100  85.63000
## 98     98  2644.710      6.000000  56.6100  86.52000
## 99     99  2010.860      6.000000  56.2300  81.15000
## 100   100  2142.120      6.000000  56.6100  85.83000
## 101   101  2059.460      6.000000  56.6100  88.17000
## 102   102  2391.750      6.000000  56.6100  85.51000
## 103   103  2517.580      6.000000  57.3800  84.82000
## 104   104  2822.250      6.000000  57.7600  79.23000
## 105   105  3303.550      6.000000  58.5300  80.16000
## 106   106  3137.000      6.000000  61.2000  78.35000
## 107   107  3461.090      6.000000  61.9700  78.17000
## 108   108  3310.800      6.000000  62.3500  76.65000
## 109   109  3461.100      6.000000  63.1200  76.30000
## 110   110  3611.430      6.000000  64.2700  74.78000
## 111   111  3491.650      6.000000  64.6500  77.86000
## 112   112  3541.880      6.000000  65.8000  79.46000
## 113   113  3463.320      6.000000  65.0300  80.36000
## 114   114  3607.990      6.000000  65.0300  81.07000
## 115   115  3745.920      6.000000  65.0300  81.87000
## 116   116  3461.170      6.000000  65.8000  86.59000
## 117   117  3479.770      6.000000  66.5600  86.02000
## 118   118  3495.720      6.000000  68.0900  81.54000
## 119   119  3531.140      6.000000  68.0900  83.20000
## 120   120  3504.320      6.000000  68.4700  78.72000
## 121   121  3629.800      6.000000  69.2400  77.27000
## 122   122  3793.460      6.000000  69.6200  81.19000
## 123   123  4065.660      6.000000  70.7700  79.03000
## 124   124  4206.660      6.000000  71.9200  77.73000
## 125   125  4450.500      6.000000  70.7700  76.89000
## 126   126  4888.110      6.000000  70.7700  75.86000
## 127   127  5159.400      6.000000  71.1500  72.93000
## 128   128  4851.800      6.000000  71.5300  74.64000
## 129   129  4747.570      6.000000  72.3000  74.30000
## 130   130  4793.300      6.000000  73.8300  73.90000
## 131   131  4550.040      6.000000  74.2100  74.12000
## 132   132  4811.930      6.000000  75.3600  78.55000
## 133   133  4916.610      6.000000  75.7400  76.17000
## 134   134  5343.290      6.000000  76.1200  78.38000
## 135   135  5486.720      6.000000  75.3600  80.18000
## 136   136  5484.920      6.000000  75.7400  79.29000
## 137   137  5540.260      9.500000  76.1200  78.74000
## 138   138  5927.550      9.500000  76.8900  79.00000
## 139   139  5888.490      9.000000  78.4200  78.78000
## 140   140  5655.940      9.000000  78.8000  83.04000
## 141   141  5083.600      9.000000  79.5700  81.63000
## 142   142  5372.190      9.000000  81.1000  82.64000
## 143   143  5848.750      9.000000  81.8600  81.21000
## 144   144  5798.480      9.000000  82.2400  79.94000
## 145   145  5476.430      9.000000  83.0100  79.92000
## 146   146  5536.010      9.000000  83.3900  80.15000
## 147   147  5526.620      9.000000  83.7700  79.77000
## 148   148  5708.320      9.000000  84.5400  79.21000
## 149   149  5784.940      8.750000  85.3000  81.95000
## 150   150  5575.840      8.500000  85.6900  83.22000
## 151   151  5375.040      8.500000  86.4500  81.75000
## 152   152  5468.660      8.250000  87.2200  83.26000
## 153   153  5817.690      8.250000  88.3600  83.14000
## 154   154  6292.380     10.250000  89.8900  81.45000
## 155   155  6836.670     10.250000  90.6600  82.09000
## 156   156  6926.830      9.500000  91.0400  80.22000
## 157   157  6497.770      8.750000  92.1900  80.19000
## 158   158  6435.780      8.750000  92.9600  80.68000
## 159   159  6534.280      8.750000  91.4200  80.03000
## 160   160  6344.000      9.000000  90.6600  81.31000
## 161   161  6529.280      9.000000  91.0400  79.69000
## 162   162  6343.000      9.000000  91.4200  80.10000
## 163   163  6329.600      9.000000  92.5700  79.47000
## 164   164  6273.130      9.000000  93.3400  80.37000
## 165   165  6471.050      9.000000  94.1000  79.78000
## 166   166  6320.510      9.000000  96.4000  81.46000
## 167   167  6092.560      9.000000  96.7800  82.75000
## 168   168  5835.690      9.000000  96.7800  85.94000
## 169   169  5280.840      9.000000  96.7800  86.92000
## 170   170  4748.530      9.000000  96.7800  88.36000
## 171   171  3806.550      9.000000  96.7800  90.27000
## 172   172  2927.200      8.750000  97.1600  94.80000
## 173   173  3398.510      8.750000  96.7800  95.32000
## 174   174  3299.230      8.500000  97.1600  98.36000
## 175   175  3611.030      8.500000  97.9300  94.60000
## 176   176  3988.780      8.500000  98.6900  96.91000
## 177   177  3915.300      8.250000  99.8400  95.48000
## 178   178  3458.510      8.250000 100.6100  97.34000
## 179   179  2973.160      8.250000 100.9900  95.82000
## 180   180  3064.430      8.250000 101.7500  96.35000
## 181   181  3055.950      7.750000 102.9000  96.95000
## 182   182  2847.430      7.750000 103.2800 100.17000
## 183   183  2435.400      7.750000 102.9000  98.63000
## 184   184  2004.000      7.750000 102.9000  99.61000
## 185   185  2117.580      7.750000 102.1400  98.21000
## 186   186  2503.950      7.750000 102.5200  94.59000
## 187   187  2708.630      7.000000 103.6700  93.08000
## 188   188  3072.750      7.000000 105.2000  95.89000
## 189   189  3208.660      7.000000 105.9600  96.14000
## 190   190  2966.280      7.000000 107.1100  95.53000
## 191   191  3004.160      7.000000 106.3400  96.02000
## 192   192  3006.050      7.000000 105.9600  95.46000
## 193   193  3290.460      6.750000 106.3400  98.44000
## 194   194  3056.290      6.750000 105.9600 101.50000
## 195   195  3572.840      6.750000 105.2000 102.21000
## 196   196  3649.890      6.750000 104.8100  99.51000
## 197   197  3647.030      6.750000 104.8100 101.12000
## 198   198  3355.090      6.750000 105.2000 100.35000
## 199   199  3365.040      6.500000 105.9600  99.05000
## 200   200  3213.830      6.500000 106.3400  96.92000
## 201   201  2975.010      6.500000 107.1100  95.63000
## 202   202  3071.230      6.500000 109.0200  92.86000
## 203   203  3194.460      6.250000 109.0200  92.67000
## 204   204  3413.190      6.250000 109.0200  93.08000
## 205   205  3574.530      6.250000 109.7900  94.55000
## 206   206  3887.810      6.250000 110.1700  93.05000
## 207   207  3930.990      6.250000 109.4000  92.12000
## 208   208  4215.160      6.250000 110.1700  89.13000
## 209   209  4085.160      6.250000 109.7900  90.61000
## 210   210  4171.720      6.250000 109.7900  89.97000
## 211   211  4516.930      6.250000 110.1700  91.84000
## 212   212  4959.750      6.250000 110.5500  93.98000
## 213   213  4879.750      6.500000 111.3200  94.64000
## 214   214  4992.510      6.500000 115.1400  94.49000
## 215   215  4942.530      6.750000 115.1400  95.14000
## 216   216  5448.550      6.750000 115.1400  95.13000
## 217   217  5648.690      6.750000 115.5200  97.13000
## 218   218  4476.090      6.750000 115.5200  97.27000
## 219   219  3822.070      6.750000 115.1400  96.17000
## 220   220  4003.080      6.750000 117.4400  95.58000
## 221   221  4352.940      6.500000 117.4400  96.16000
## 222   222  4432.040      6.500000 118.2000  97.28000
## 223   223  4761.330      6.250000 119.3500  97.48000
## 224   224  4664.020      6.250000 120.1100  97.75000
## 225   225  4149.670      6.000000 120.8800  96.13000
## 226   226  4230.220      6.000000 122.0300  98.52000
## 227   227  4102.970      5.650000 122.4100  98.92000
## 228   228  4282.870      5.650000 123.1800  99.38000
## 229   229  4069.140      5.400000 124.3200  97.35000
## 230   230  4034.138      5.582987 124.9278  97.17034
## 231   231  4048.191      5.747641 125.6874  96.98876
## 232   232  4073.002      5.866770 126.2105  96.80526
## 233   233  4100.240      5.942698 126.5170  96.61980
## 234   234  4128.058      6.000835 126.9328  96.43234
## 235   235  4156.022      6.042542 127.2915  96.24285
## 236   236  4184.026      6.073088 127.5671  96.05129
## 237   237  4212.040      6.094774 127.8683  95.85763
## 238   238  4240.057      6.110654 128.1604  95.66182
## 239   239  4268.075      6.122249 128.4034  95.46385
#forecast cmort using mlp with forecasted xreg (don't need to forecast week.)
gold10DF = data.frame(Date = ts(seq(1,229,1)),crude_oil = ts(gold10$Crude_Oil), interest_rate = ts(gold10$Interest_Rate), CPI = ts(gold10$CPI),  USD_index = ts(gold10$USD_Index))
fit.mlp = mlp(ts(gold10$Gold_Price),reps = 50,comb = "mean",xreg = gold10DF)

fit.mlp
## MLP fit with 5 hidden nodes and 50 repetitions.
## Series modelled in differences: D1.
## Univariate lags: (1,2,3,4)
## 4 regressors included.
## - Regressor 1 lags: (2,4)
## - Regressor 2 lags: (4)
## - Regressor 3 lags: (1,4)
## - Regressor 4 lags: (1,3)
## Forecast combined using the mean operator.
## MSE: 106810.9364.
plot(fit.mlp)

#CMDF = data.frame(Week = ts(CM$Week),temp = ts(CM$temp), part = ts(CM$part), temp_1 = ts(CM$temp_1))
fore.mlp = forecast(fit.mlp, h = 10, xreg = GDF_fore)
plot(fore.mlp)

ASE = mean((gold$Gold_Price[230:239] - fore.mlp$mean)^2)
ASE # 20,596,925
## [1] 16621771
#Plot
plot(seq(1,239,1), gold$Gold_Price, type = "l",xlim = c(0,250), ylab = "Gold Price", main = "10 Month Gold Price Forecast MLP", xlab="Month")
lines(seq(230,239,1), fore.mlp$mean, type = "l", col = "red")

GDF_vars = data.frame(Month = ts(seq(1,239,1)),crude_oil = ts(gold$Crude_Oil), interest_rate = ts(gold$Interest_Rate), CPI = ts(gold$CPI), USD_index = ts(gold$USD_Index))
GDF_vars
##     Month crude_oil interest_rate    CPI USD_index
## 1       1   1455.51          8.00  37.23    116.65
## 2       2   1512.47          8.00  37.31    115.24
## 3       3   1178.11          8.00  36.98    109.56
## 4       4   1208.18          8.00  36.90    110.52
## 5       5   1267.18          7.50  36.73    112.01
## 6       6   1166.45          7.00  36.90    117.37
## 7       7   1203.33          7.00  37.15    115.85
## 8       8   1292.57          7.00  37.40    119.07
## 9       9   1267.73          7.00  37.89    119.43
## 10     10   1169.12          7.00  38.39    117.18
## 11     11   1216.80          7.00  38.64    113.42
## 12     12   1201.16          7.00  38.56    113.48
## 13     13    995.46          6.50  38.80    114.86
## 14     14    897.07          6.50  39.14    116.13
## 15     15    887.42          6.50  38.89    116.75
## 16     16    925.63          6.50  38.72    120.24
## 17     17    972.86          6.50  38.64    119.16
## 18     18   1152.20          6.50  38.80    118.62
## 19     19   1244.02          6.50  38.89    115.19
## 20     20   1257.83          6.50  39.14    111.81
## 21     21   1199.06          6.50  39.47    106.11
## 22     22   1255.67          6.50  39.88    107.41
## 23     23   1301.25          6.50  40.13    106.98
## 24     24   1369.92          6.50  40.21    106.87
## 25     25   1331.61          6.50  40.38    106.64
## 26     26   1184.18          6.25  40.55    106.41
## 27     27   1342.56          6.25  40.13    101.85
## 28     28   1473.85          6.25  40.05     99.91
## 29     29   1569.55          6.25  40.13     99.71
## 30     30   1446.38          6.25  40.38     99.06
## 31     31   1210.97          6.25  40.88     97.19
## 32     32   1226.99          6.00  40.96     93.27
## 33     33   1304.45          6.00  41.21     94.73
## 34     34   1321.85          6.00  41.54     96.89
## 35     35   1363.37          6.00  41.38     98.10
## 36     36   1232.46          6.00  41.38     92.85
## 37     37   1316.78          6.00  41.71     92.73
## 38     38   1325.54          6.00  41.79     90.21
## 39     39   1366.36          6.00  41.62     86.92
## 40     40   1425.74          6.00  41.79     87.20
## 41     41   1418.36          6.00  41.79     87.31
## 42     42   1515.65          6.00  41.79     87.61
## 43     43   1480.99          6.00  41.79     90.48
## 44     44   1699.29          6.00  42.12     88.95
## 45     45   1617.64          6.00  42.45     88.80
## 46     46   1744.59          6.00  42.87     89.96
## 47     47   1950.09          6.00  43.28     88.94
## 48     48   1917.68          6.00  43.37     87.36
## 49     49   2146.34          6.00  43.61     84.91
## 50     50   1900.58          6.00  43.53     81.82
## 51     51   1717.00          6.00  43.20     80.85
## 52     52   1880.23          6.00  43.61     83.60
## 53     53   1957.60          6.00  43.53     82.51
## 54     54   2225.57          6.00  43.53     84.06
## 55     55   2215.05          6.00  43.86     84.43
## 56     56   2080.20          6.00  43.70     87.76
## 57     57   2348.85          6.00  43.86     89.11
## 58     58   2454.20          6.00  44.61     89.35
## 59     59   2700.01          6.00  44.77     87.58
## 60     60   2709.21          6.00  44.94     89.52
## 61     61   2608.22          6.00  45.44     90.07
## 62     62   2516.77          6.00  45.85     91.57
## 63     63   2576.49          6.00  45.60     91.17
## 64     64   2773.13          6.00  45.52     88.96
## 65     65   2646.56          6.00  45.52     90.11
## 66     66   2709.89          6.00  45.52     89.73
## 67     67   3055.21          6.00  45.90     86.11
## 68     68   3118.70          6.00  46.29     84.72
## 69     69   3145.13          6.00  47.05     85.22
## 70     70   3365.75          6.00  47.43     85.30
## 71     71   3341.97          6.00  47.43     85.05
## 72     72   2865.03          6.00  47.82     85.97
## 73     73   2633.08          6.00  48.58     85.32
## 74     74   2607.99          6.00  48.58     82.92
## 75     75   2722.26          6.00  48.58     83.72
## 76     76   2373.05          6.00  48.58     84.61
## 77     77   2541.99          6.00  48.96     83.57
## 78     78   2667.95          6.00  48.58     82.93
## 79     79   2742.35          6.00  48.96     81.45
## 80     80   2658.01          6.00  49.35     82.30
## 81     81   2779.56          6.00  49.73     81.92
## 82     82   2974.64          6.00  50.49     80.77
## 83     83   2862.54          6.00  50.88     80.79
## 84     84   3096.50          6.00  50.88     77.72
## 85     85   3238.90          6.00  51.26     76.48
## 86     86   3602.45          6.00  51.26     76.15
## 87     87   3530.67          6.00  51.26     76.69
## 88     88   3570.71          6.00  51.26     75.18
## 89     89   3710.34          6.00  51.64     73.71
## 90     90   4109.92          6.00  52.41     71.80
## 91     91   4353.72          6.00  52.79     72.51
## 92     92   5165.85          6.00  53.17     72.88
## 93     93   5631.69          6.00  53.55     72.46
## 94     94   5689.98          6.00  54.70     73.23
## 95     95   4919.52          6.00  55.47     77.38
## 96     96   4540.91          6.00  55.85     79.45
## 97     97   3535.80          6.00  56.61     85.63
## 98     98   2644.71          6.00  56.61     86.52
## 99     99   2010.86          6.00  56.23     81.15
## 100   100   2142.12          6.00  56.61     85.83
## 101   101   2059.46          6.00  56.61     88.17
## 102   102   2391.75          6.00  56.61     85.51
## 103   103   2517.58          6.00  57.38     84.82
## 104   104   2822.25          6.00  57.76     79.23
## 105   105   3303.55          6.00  58.53     80.16
## 106   106   3137.00          6.00  61.20     78.35
## 107   107   3461.09          6.00  61.97     78.17
## 108   108   3310.80          6.00  62.35     76.65
## 109   109   3461.10          6.00  63.12     76.30
## 110   110   3611.43          6.00  64.27     74.78
## 111   111   3491.65          6.00  64.65     77.86
## 112   112   3541.88          6.00  65.80     79.46
## 113   113   3463.32          6.00  65.03     80.36
## 114   114   3607.99          6.00  65.03     81.07
## 115   115   3745.92          6.00  65.03     81.87
## 116   116   3461.17          6.00  65.80     86.59
## 117   117   3479.77          6.00  66.56     86.02
## 118   118   3495.72          6.00  68.09     81.54
## 119   119   3531.14          6.00  68.09     83.20
## 120   120   3504.32          6.00  68.47     78.72
## 121   121   3629.80          6.00  69.24     77.27
## 122   122   3793.46          6.00  69.62     81.19
## 123   123   4065.66          6.00  70.77     79.03
## 124   124   4206.66          6.00  71.92     77.73
## 125   125   4450.50          6.00  70.77     76.89
## 126   126   4888.11          6.00  70.77     75.86
## 127   127   5159.40          6.00  71.15     72.93
## 128   128   4851.80          6.00  71.53     74.64
## 129   129   4747.57          6.00  72.30     74.30
## 130   130   4793.30          6.00  73.83     73.90
## 131   131   4550.04          6.00  74.21     74.12
## 132   132   4811.93          6.00  75.36     78.55
## 133   133   4916.61          6.00  75.74     76.17
## 134   134   5343.29          6.00  76.12     78.38
## 135   135   5486.72          6.00  75.36     80.18
## 136   136   5484.92          6.00  75.74     79.29
## 137   137   5540.26          9.50  76.12     78.74
## 138   138   5927.55          9.50  76.89     79.00
## 139   139   5888.49          9.00  78.42     78.78
## 140   140   5655.94          9.00  78.80     83.04
## 141   141   5083.60          9.00  79.57     81.63
## 142   142   5372.19          9.00  81.10     82.64
## 143   143   5848.75          9.00  81.86     81.21
## 144   144   5798.48          9.00  82.24     79.94
## 145   145   5476.43          9.00  83.01     79.92
## 146   146   5536.01          9.00  83.39     80.15
## 147   147   5526.62          9.00  83.77     79.77
## 148   148   5708.32          9.00  84.54     79.21
## 149   149   5784.94          8.75  85.30     81.95
## 150   150   5575.84          8.50  85.69     83.22
## 151   151   5375.04          8.50  86.45     81.75
## 152   152   5468.66          8.25  87.22     83.26
## 153   153   5817.69          8.25  88.36     83.14
## 154   154   6292.38         10.25  89.89     81.45
## 155   155   6836.67         10.25  90.66     82.09
## 156   156   6926.83          9.50  91.04     80.22
## 157   157   6497.77          8.75  92.19     80.19
## 158   158   6435.78          8.75  92.96     80.68
## 159   159   6534.28          8.75  91.42     80.03
## 160   160   6344.00          9.00  90.66     81.31
## 161   161   6529.28          9.00  91.04     79.69
## 162   162   6343.00          9.00  91.42     80.10
## 163   163   6329.60          9.00  92.57     79.47
## 164   164   6273.13          9.00  93.34     80.37
## 165   165   6471.05          9.00  94.10     79.78
## 166   166   6320.51          9.00  96.40     81.46
## 167   167   6092.56          9.00  96.78     82.75
## 168   168   5835.69          9.00  96.78     85.94
## 169   169   5280.84          9.00  96.78     86.92
## 170   170   4748.53          9.00  96.78     88.36
## 171   171   3806.55          9.00  96.78     90.27
## 172   172   2927.20          8.75  97.16     94.80
## 173   173   3398.51          8.75  96.78     95.32
## 174   174   3299.23          8.50  97.16     98.36
## 175   175   3611.03          8.50  97.93     94.60
## 176   176   3988.78          8.50  98.69     96.91
## 177   177   3915.30          8.25  99.84     95.48
## 178   178   3458.51          8.25 100.61     97.34
## 179   179   2973.16          8.25 100.99     95.82
## 180   180   3064.43          8.25 101.75     96.35
## 181   181   3055.95          7.75 102.90     96.95
## 182   182   2847.43          7.75 103.28    100.17
## 183   183   2435.40          7.75 102.90     98.63
## 184   184   2004.00          7.75 102.90     99.61
## 185   185   2117.58          7.75 102.14     98.21
## 186   186   2503.95          7.75 102.52     94.59
## 187   187   2708.63          7.00 103.67     93.08
## 188   188   3072.75          7.00 105.20     95.89
## 189   189   3208.66          7.00 105.96     96.14
## 190   190   2966.28          7.00 107.11     95.53
## 191   191   3004.16          7.00 106.34     96.02
## 192   192   3006.05          7.00 105.96     95.46
## 193   193   3290.46          6.75 106.34     98.44
## 194   194   3056.29          6.75 105.96    101.50
## 195   195   3572.84          6.75 105.20    102.21
## 196   196   3649.89          6.75 104.81     99.51
## 197   197   3647.03          6.75 104.81    101.12
## 198   198   3355.09          6.75 105.20    100.35
## 199   199   3365.04          6.50 105.96     99.05
## 200   200   3213.83          6.50 106.34     96.92
## 201   201   2975.01          6.50 107.11     95.63
## 202   202   3071.23          6.50 109.02     92.86
## 203   203   3194.46          6.25 109.02     92.67
## 204   204   3413.19          6.25 109.02     93.08
## 205   205   3574.53          6.25 109.79     94.55
## 206   206   3887.81          6.25 110.17     93.05
## 207   207   3930.99          6.25 109.40     92.12
## 208   208   4215.16          6.25 110.17     89.13
## 209   209   4085.16          6.25 109.79     90.61
## 210   210   4171.72          6.25 109.79     89.97
## 211   211   4516.93          6.25 110.17     91.84
## 212   212   4959.75          6.25 110.55     93.98
## 213   213   4879.75          6.50 111.32     94.64
## 214   214   4992.51          6.50 115.14     94.49
## 215   215   4942.53          6.75 115.14     95.14
## 216   216   5448.55          6.75 115.14     95.13
## 217   217   5648.69          6.75 115.52     97.13
## 218   218   4476.09          6.75 115.52     97.27
## 219   219   3822.07          6.75 115.14     96.17
## 220   220   4003.08          6.75 117.44     95.58
## 221   221   4352.94          6.50 117.44     96.16
## 222   222   4432.04          6.50 118.20     97.28
## 223   223   4761.33          6.25 119.35     97.48
## 224   224   4664.02          6.25 120.11     97.75
## 225   225   4149.67          6.00 120.88     96.13
## 226   226   4230.22          6.00 122.03     98.52
## 227   227   4102.97          5.65 122.41     98.92
## 228   228   4282.87          5.65 123.18     99.38
## 229   229   4069.14          5.40 124.32     97.35
## 230   230   4314.32          5.40 125.47     98.27
## 231   231   4509.77          5.40 126.24     96.39
## 232   232   4395.91          5.40 126.24     97.39
## 233   233   3811.78          5.40 125.47     98.13
## 234   234   2392.98          4.65 124.71     99.05
## 235   235   1603.02          4.65 125.85     99.57
## 236   236   2298.55          4.25 126.24     98.34
## 237   237   2987.46          4.25 127.00     97.39
## 238   238   3156.01          4.25 128.53     93.35
## 239   239   3243.75          4.25 129.30     92.14
#roll.win.rmse.nn.wgehp(series=gold$Gold_Price, horizon = 10, fit_model=fit.mlp, xreg_input = GDF_fore)

# fit = mlp(ts(series[i:(i+(trainingSize-1))]), model = fit_model)

# x.n <- dim(xreg)[2]
#xm.n <- length(model$xreg.minmax)

#if (x.n != xm.n){
#          stop("Previous model xreg specification and new xreg inputs do not match.")
#        }
#Ensemble CODE - SHORT TERM 

ensemble  = (preds$fcst$y1[,1] + fore.mlp$mean)/2

#Plot
plot(seq(1,239,1), gold$Gold_Price, type = "l",xlim = c(0,239), ylab = "Gold Price", main = "10 Month Gold Price Forecast Ensemble", xlab='Month')
lines(seq(230,239,1), ensemble, type = "l", col = "red")

ASE = mean((gold$Gold_Price[230:239] - ensemble)^2)
ASE #23180638
## [1] 22147700
MULTIVARIATE (VAR, NN, ENSEMBLE) SHORT TERM 10 MONTH AHEAD
#short term -- VAR - ahead 10 months

X =(cbind(gold$Gold_Price, gold$Crude_Oil,gold$Interest_Rate, gold$CPI, gold$USD_Index))

VARselect(X, lag.max=10, type='const', season=NULL, exogen=NULL)
## $selection
## AIC(n)  HQ(n)  SC(n) FPE(n) 
##      2      1      1      2 
## 
## $criteria
##                   1            2            3            4            5
## AIC(n) 2.252236e+01 2.238532e+01 2.240280e+01 2.252922e+01 2.252664e+01
## HQ(n)  2.270384e+01 2.271802e+01 2.288672e+01 2.316437e+01 2.331303e+01
## SC(n)  2.297220e+01 2.321001e+01 2.360235e+01 2.410363e+01 2.447592e+01
## FPE(n) 6.044561e+09 5.272064e+09 5.369151e+09 6.101494e+09 6.100020e+09
##                   6            7            8            9           10
## AIC(n) 2.254568e+01 2.262177e+01 2.249641e+01 2.260776e+01 2.266344e+01
## HQ(n)  2.348330e+01 2.371062e+01 2.373648e+01 2.399906e+01 2.420596e+01
## SC(n)  2.486982e+01 2.532077e+01 2.557026e+01 2.605648e+01 2.648702e+01
## FPE(n) 6.238744e+09 6.764269e+09 6.005345e+09 6.767855e+09 7.229206e+09
#Varselect picks p=2
lsfit=VAR(X, p=2, type='const')
## Warning in VAR(X, p = 2, type = "const"): No column names supplied in y, using: y1, y2, y3, y4, y5 , instead.
preds=predict(lsfit, n.ahead=10)
preds
## $y1
##           fcst    lower    upper       CI
##  [1,] 54678.87 53285.24 56072.50 1393.632
##  [2,] 56309.49 54187.38 58431.61 2122.116
##  [3,] 57968.86 55279.04 60658.67 2689.817
##  [4,] 59635.45 56433.78 62837.13 3201.675
##  [5,] 61299.57 57609.92 64989.23 3689.656
##  [6,] 62958.41 58792.77 67124.05 4165.636
##  [7,] 64608.24 59971.93 69244.55 4636.308
##  [8,] 66244.49 61138.60 71350.38 5105.888
##  [9,] 67862.53 62285.58 73439.47 5576.944
## [10,] 69458.02 63407.09 75508.95 6050.932
## 
## $y2
##           fcst    lower    upper        CI
##  [1,] 3597.457 3071.313 4123.601  526.1437
##  [2,] 4078.698 3207.431 4949.966  871.2674
##  [3,] 4617.520 3502.915 5732.126 1114.6055
##  [4,] 5165.417 3885.987 6444.847 1279.4299
##  [5,] 5699.507 4308.744 7090.270 1390.7629
##  [6,] 6212.183 4744.020 7680.345 1468.1622
##  [7,] 6702.560 5177.174 8227.947 1525.3866
##  [8,] 7172.301 5600.621 8743.980 1571.6795
##  [9,] 7623.756 6010.663 9236.850 1613.0933
## [10,] 8059.165 6405.635 9712.694 1653.5295
## 
## $y3
##           fcst    lower    upper        CI
##  [1,] 4.263918 3.691178 4.836657 0.5727395
##  [2,] 4.386316 3.582265 5.190366 0.8040505
##  [3,] 4.549564 3.587544 5.511583 0.9620195
##  [4,] 4.739558 3.650935 5.828182 1.0886234
##  [5,] 4.956155 3.759438 6.152873 1.1967173
##  [6,] 5.197444 3.906475 6.488413 1.2909692
##  [7,] 5.460268 4.086500 6.834037 1.3737685
##  [8,] 5.741467 4.294810 7.188124 1.4466568
##  [9,] 6.038197 4.527385 7.549009 1.5108121
## [10,] 6.347951 4.780683 7.915219 1.5672677
## 
## $y4
##           fcst    lower    upper       CI
##  [1,] 130.1508 129.0038 131.2978 1.147011
##  [2,] 131.1245 129.3507 132.8983 1.773828
##  [3,] 132.1890 129.9341 134.4438 2.254852
##  [4,] 133.3231 130.6688 135.9774 2.654309
##  [5,] 134.5171 131.5157 137.5185 3.001405
##  [6,] 135.7659 132.4540 139.0778 3.311938
##  [7,] 137.0664 133.4707 140.6622 3.595723
##  [8,] 138.4168 134.5574 142.2763 3.859480
##  [9,] 139.8157 135.7076 143.9238 4.108141
## [10,] 141.2618 136.9162 145.6073 4.345536
## 
## $y5
##           fcst    lower    upper        CI
##  [1,] 90.70505 86.75759 94.65252  3.947465
##  [2,] 88.63472 83.08249 94.18696  5.552236
##  [3,] 86.41642 79.70204 93.13079  6.714373
##  [4,] 84.21105 76.56617 91.85592  7.644875
##  [5,] 82.05884 73.62869 90.48899  8.430149
##  [6,] 79.97463 70.85832 89.09094  9.116313
##  [7,] 77.96491 68.23201 87.69782  9.732906
##  [8,] 76.03179 65.73180 86.33177 10.299984
##  [9,] 74.17557 63.34402 85.00711 10.831546
## [10,] 72.39628 61.05866 83.73389 11.337616
preds$fcst$y1[1:10,1]
##  [1] 54678.87 56309.49 57968.86 59635.45 61299.57 62958.41 64608.24 66244.49
##  [9] 67862.53 69458.02
plot(seq(1,239,1), gold$Gold_Price, type='l', ylim=c(0,100000), xlim = c(0,250)) 
points(seq(240,249,1),preds$fcst$y1[1:10,1], type='l', col='red', pch=15)

fanchart(preds)

fanchart(preds, names='y1')

# Short TERM ahead forecasts

#forecast crude oil, interest rate, cpi, and usd index

# Forecast Months 240-249 for other variables
#crude
fit.mlp.crude = mlp(ts(gold$Crude_Oil),reps = 20, comb = "median")
plot(fit.mlp.crude)

fore.mlp.crude = forecast(fit.mlp.crude, h = 10)
plot(fore.mlp.crude)

#interest
fit.mlp.int = mlp(ts(gold$Interest_Rate),reps = 20, comb = "median")
fore.mlp.int = forecast(fit.mlp.int, h = 10)
plot(fore.mlp.int)

#CPI
fit.mlp.cpi = mlp(ts(gold$CPI),reps = 20, comb = "median")
plot(fit.mlp.cpi)

fore.mlp.cpi = forecast(fit.mlp.cpi, h = 10)
plot(fore.mlp.cpi)

#USD
fit.mlp.usd = mlp(ts(gold$USD_Index),reps = 20, comb = "median")
fore.mlp.usd = forecast(fit.mlp.usd, h = 10)
plot(fore.mlp.usd)

#package them up in data frame.
#fore.mlp.temp1 = dplyr::lag(as.vector(fore.mlp.temp$mean),1)
GDF_fore = data.frame(Month = ts(seq(1,249,1)),crude_oil = ts(c(gold$Crude_Oil,fore.mlp.crude$mean)), interest_rate = ts(c(gold$Interest_Rate,fore.mlp.int$mean)), CPI = ts(c(gold$CPI,fore.mlp.cpi$mean)), USD_index = ts(c(gold$USD_Index,fore.mlp.usd$mean)))
GDF_fore
##     Month crude_oil interest_rate      CPI USD_index
## 1       1  1455.510      8.000000  37.2300 116.65000
## 2       2  1512.470      8.000000  37.3100 115.24000
## 3       3  1178.110      8.000000  36.9800 109.56000
## 4       4  1208.180      8.000000  36.9000 110.52000
## 5       5  1267.180      7.500000  36.7300 112.01000
## 6       6  1166.450      7.000000  36.9000 117.37000
## 7       7  1203.330      7.000000  37.1500 115.85000
## 8       8  1292.570      7.000000  37.4000 119.07000
## 9       9  1267.730      7.000000  37.8900 119.43000
## 10     10  1169.120      7.000000  38.3900 117.18000
## 11     11  1216.800      7.000000  38.6400 113.42000
## 12     12  1201.160      7.000000  38.5600 113.48000
## 13     13   995.460      6.500000  38.8000 114.86000
## 14     14   897.070      6.500000  39.1400 116.13000
## 15     15   887.420      6.500000  38.8900 116.75000
## 16     16   925.630      6.500000  38.7200 120.24000
## 17     17   972.860      6.500000  38.6400 119.16000
## 18     18  1152.200      6.500000  38.8000 118.62000
## 19     19  1244.020      6.500000  38.8900 115.19000
## 20     20  1257.830      6.500000  39.1400 111.81000
## 21     21  1199.060      6.500000  39.4700 106.11000
## 22     22  1255.670      6.500000  39.8800 107.41000
## 23     23  1301.250      6.500000  40.1300 106.98000
## 24     24  1369.920      6.500000  40.2100 106.87000
## 25     25  1331.610      6.500000  40.3800 106.64000
## 26     26  1184.180      6.250000  40.5500 106.41000
## 27     27  1342.560      6.250000  40.1300 101.85000
## 28     28  1473.850      6.250000  40.0500  99.91000
## 29     29  1569.550      6.250000  40.1300  99.71000
## 30     30  1446.380      6.250000  40.3800  99.06000
## 31     31  1210.970      6.250000  40.8800  97.19000
## 32     32  1226.990      6.000000  40.9600  93.27000
## 33     33  1304.450      6.000000  41.2100  94.73000
## 34     34  1321.850      6.000000  41.5400  96.89000
## 35     35  1363.370      6.000000  41.3800  98.10000
## 36     36  1232.460      6.000000  41.3800  92.85000
## 37     37  1316.780      6.000000  41.7100  92.73000
## 38     38  1325.540      6.000000  41.7900  90.21000
## 39     39  1366.360      6.000000  41.6200  86.92000
## 40     40  1425.740      6.000000  41.7900  87.20000
## 41     41  1418.360      6.000000  41.7900  87.31000
## 42     42  1515.650      6.000000  41.7900  87.61000
## 43     43  1480.990      6.000000  41.7900  90.48000
## 44     44  1699.290      6.000000  42.1200  88.95000
## 45     45  1617.640      6.000000  42.4500  88.80000
## 46     46  1744.590      6.000000  42.8700  89.96000
## 47     47  1950.090      6.000000  43.2800  88.94000
## 48     48  1917.680      6.000000  43.3700  87.36000
## 49     49  2146.340      6.000000  43.6100  84.91000
## 50     50  1900.580      6.000000  43.5300  81.82000
## 51     51  1717.000      6.000000  43.2000  80.85000
## 52     52  1880.230      6.000000  43.6100  83.60000
## 53     53  1957.600      6.000000  43.5300  82.51000
## 54     54  2225.570      6.000000  43.5300  84.06000
## 55     55  2215.050      6.000000  43.8600  84.43000
## 56     56  2080.200      6.000000  43.7000  87.76000
## 57     57  2348.850      6.000000  43.8600  89.11000
## 58     58  2454.200      6.000000  44.6100  89.35000
## 59     59  2700.010      6.000000  44.7700  87.58000
## 60     60  2709.210      6.000000  44.9400  89.52000
## 61     61  2608.220      6.000000  45.4400  90.07000
## 62     62  2516.770      6.000000  45.8500  91.57000
## 63     63  2576.490      6.000000  45.6000  91.17000
## 64     64  2773.130      6.000000  45.5200  88.96000
## 65     65  2646.560      6.000000  45.5200  90.11000
## 66     66  2709.890      6.000000  45.5200  89.73000
## 67     67  3055.210      6.000000  45.9000  86.11000
## 68     68  3118.700      6.000000  46.2900  84.72000
## 69     69  3145.130      6.000000  47.0500  85.22000
## 70     70  3365.750      6.000000  47.4300  85.30000
## 71     71  3341.970      6.000000  47.4300  85.05000
## 72     72  2865.030      6.000000  47.8200  85.97000
## 73     73  2633.080      6.000000  48.5800  85.32000
## 74     74  2607.990      6.000000  48.5800  82.92000
## 75     75  2722.260      6.000000  48.5800  83.72000
## 76     76  2373.050      6.000000  48.5800  84.61000
## 77     77  2541.990      6.000000  48.9600  83.57000
## 78     78  2667.950      6.000000  48.5800  82.93000
## 79     79  2742.350      6.000000  48.9600  81.45000
## 80     80  2658.010      6.000000  49.3500  82.30000
## 81     81  2779.560      6.000000  49.7300  81.92000
## 82     82  2974.640      6.000000  50.4900  80.77000
## 83     83  2862.540      6.000000  50.8800  80.79000
## 84     84  3096.500      6.000000  50.8800  77.72000
## 85     85  3238.900      6.000000  51.2600  76.48000
## 86     86  3602.450      6.000000  51.2600  76.15000
## 87     87  3530.670      6.000000  51.2600  76.69000
## 88     88  3570.710      6.000000  51.2600  75.18000
## 89     89  3710.340      6.000000  51.6400  73.71000
## 90     90  4109.920      6.000000  52.4100  71.80000
## 91     91  4353.720      6.000000  52.7900  72.51000
## 92     92  5165.850      6.000000  53.1700  72.88000
## 93     93  5631.690      6.000000  53.5500  72.46000
## 94     94  5689.980      6.000000  54.7000  73.23000
## 95     95  4919.520      6.000000  55.4700  77.38000
## 96     96  4540.910      6.000000  55.8500  79.45000
## 97     97  3535.800      6.000000  56.6100  85.63000
## 98     98  2644.710      6.000000  56.6100  86.52000
## 99     99  2010.860      6.000000  56.2300  81.15000
## 100   100  2142.120      6.000000  56.6100  85.83000
## 101   101  2059.460      6.000000  56.6100  88.17000
## 102   102  2391.750      6.000000  56.6100  85.51000
## 103   103  2517.580      6.000000  57.3800  84.82000
## 104   104  2822.250      6.000000  57.7600  79.23000
## 105   105  3303.550      6.000000  58.5300  80.16000
## 106   106  3137.000      6.000000  61.2000  78.35000
## 107   107  3461.090      6.000000  61.9700  78.17000
## 108   108  3310.800      6.000000  62.3500  76.65000
## 109   109  3461.100      6.000000  63.1200  76.30000
## 110   110  3611.430      6.000000  64.2700  74.78000
## 111   111  3491.650      6.000000  64.6500  77.86000
## 112   112  3541.880      6.000000  65.8000  79.46000
## 113   113  3463.320      6.000000  65.0300  80.36000
## 114   114  3607.990      6.000000  65.0300  81.07000
## 115   115  3745.920      6.000000  65.0300  81.87000
## 116   116  3461.170      6.000000  65.8000  86.59000
## 117   117  3479.770      6.000000  66.5600  86.02000
## 118   118  3495.720      6.000000  68.0900  81.54000
## 119   119  3531.140      6.000000  68.0900  83.20000
## 120   120  3504.320      6.000000  68.4700  78.72000
## 121   121  3629.800      6.000000  69.2400  77.27000
## 122   122  3793.460      6.000000  69.6200  81.19000
## 123   123  4065.660      6.000000  70.7700  79.03000
## 124   124  4206.660      6.000000  71.9200  77.73000
## 125   125  4450.500      6.000000  70.7700  76.89000
## 126   126  4888.110      6.000000  70.7700  75.86000
## 127   127  5159.400      6.000000  71.1500  72.93000
## 128   128  4851.800      6.000000  71.5300  74.64000
## 129   129  4747.570      6.000000  72.3000  74.30000
## 130   130  4793.300      6.000000  73.8300  73.90000
## 131   131  4550.040      6.000000  74.2100  74.12000
## 132   132  4811.930      6.000000  75.3600  78.55000
## 133   133  4916.610      6.000000  75.7400  76.17000
## 134   134  5343.290      6.000000  76.1200  78.38000
## 135   135  5486.720      6.000000  75.3600  80.18000
## 136   136  5484.920      6.000000  75.7400  79.29000
## 137   137  5540.260      9.500000  76.1200  78.74000
## 138   138  5927.550      9.500000  76.8900  79.00000
## 139   139  5888.490      9.000000  78.4200  78.78000
## 140   140  5655.940      9.000000  78.8000  83.04000
## 141   141  5083.600      9.000000  79.5700  81.63000
## 142   142  5372.190      9.000000  81.1000  82.64000
## 143   143  5848.750      9.000000  81.8600  81.21000
## 144   144  5798.480      9.000000  82.2400  79.94000
## 145   145  5476.430      9.000000  83.0100  79.92000
## 146   146  5536.010      9.000000  83.3900  80.15000
## 147   147  5526.620      9.000000  83.7700  79.77000
## 148   148  5708.320      9.000000  84.5400  79.21000
## 149   149  5784.940      8.750000  85.3000  81.95000
## 150   150  5575.840      8.500000  85.6900  83.22000
## 151   151  5375.040      8.500000  86.4500  81.75000
## 152   152  5468.660      8.250000  87.2200  83.26000
## 153   153  5817.690      8.250000  88.3600  83.14000
## 154   154  6292.380     10.250000  89.8900  81.45000
## 155   155  6836.670     10.250000  90.6600  82.09000
## 156   156  6926.830      9.500000  91.0400  80.22000
## 157   157  6497.770      8.750000  92.1900  80.19000
## 158   158  6435.780      8.750000  92.9600  80.68000
## 159   159  6534.280      8.750000  91.4200  80.03000
## 160   160  6344.000      9.000000  90.6600  81.31000
## 161   161  6529.280      9.000000  91.0400  79.69000
## 162   162  6343.000      9.000000  91.4200  80.10000
## 163   163  6329.600      9.000000  92.5700  79.47000
## 164   164  6273.130      9.000000  93.3400  80.37000
## 165   165  6471.050      9.000000  94.1000  79.78000
## 166   166  6320.510      9.000000  96.4000  81.46000
## 167   167  6092.560      9.000000  96.7800  82.75000
## 168   168  5835.690      9.000000  96.7800  85.94000
## 169   169  5280.840      9.000000  96.7800  86.92000
## 170   170  4748.530      9.000000  96.7800  88.36000
## 171   171  3806.550      9.000000  96.7800  90.27000
## 172   172  2927.200      8.750000  97.1600  94.80000
## 173   173  3398.510      8.750000  96.7800  95.32000
## 174   174  3299.230      8.500000  97.1600  98.36000
## 175   175  3611.030      8.500000  97.9300  94.60000
## 176   176  3988.780      8.500000  98.6900  96.91000
## 177   177  3915.300      8.250000  99.8400  95.48000
## 178   178  3458.510      8.250000 100.6100  97.34000
## 179   179  2973.160      8.250000 100.9900  95.82000
## 180   180  3064.430      8.250000 101.7500  96.35000
## 181   181  3055.950      7.750000 102.9000  96.95000
## 182   182  2847.430      7.750000 103.2800 100.17000
## 183   183  2435.400      7.750000 102.9000  98.63000
## 184   184  2004.000      7.750000 102.9000  99.61000
## 185   185  2117.580      7.750000 102.1400  98.21000
## 186   186  2503.950      7.750000 102.5200  94.59000
## 187   187  2708.630      7.000000 103.6700  93.08000
## 188   188  3072.750      7.000000 105.2000  95.89000
## 189   189  3208.660      7.000000 105.9600  96.14000
## 190   190  2966.280      7.000000 107.1100  95.53000
## 191   191  3004.160      7.000000 106.3400  96.02000
## 192   192  3006.050      7.000000 105.9600  95.46000
## 193   193  3290.460      6.750000 106.3400  98.44000
## 194   194  3056.290      6.750000 105.9600 101.50000
## 195   195  3572.840      6.750000 105.2000 102.21000
## 196   196  3649.890      6.750000 104.8100  99.51000
## 197   197  3647.030      6.750000 104.8100 101.12000
## 198   198  3355.090      6.750000 105.2000 100.35000
## 199   199  3365.040      6.500000 105.9600  99.05000
## 200   200  3213.830      6.500000 106.3400  96.92000
## 201   201  2975.010      6.500000 107.1100  95.63000
## 202   202  3071.230      6.500000 109.0200  92.86000
## 203   203  3194.460      6.250000 109.0200  92.67000
## 204   204  3413.190      6.250000 109.0200  93.08000
## 205   205  3574.530      6.250000 109.7900  94.55000
## 206   206  3887.810      6.250000 110.1700  93.05000
## 207   207  3930.990      6.250000 109.4000  92.12000
## 208   208  4215.160      6.250000 110.1700  89.13000
## 209   209  4085.160      6.250000 109.7900  90.61000
## 210   210  4171.720      6.250000 109.7900  89.97000
## 211   211  4516.930      6.250000 110.1700  91.84000
## 212   212  4959.750      6.250000 110.5500  93.98000
## 213   213  4879.750      6.500000 111.3200  94.64000
## 214   214  4992.510      6.500000 115.1400  94.49000
## 215   215  4942.530      6.750000 115.1400  95.14000
## 216   216  5448.550      6.750000 115.1400  95.13000
## 217   217  5648.690      6.750000 115.5200  97.13000
## 218   218  4476.090      6.750000 115.5200  97.27000
## 219   219  3822.070      6.750000 115.1400  96.17000
## 220   220  4003.080      6.750000 117.4400  95.58000
## 221   221  4352.940      6.500000 117.4400  96.16000
## 222   222  4432.040      6.500000 118.2000  97.28000
## 223   223  4761.330      6.250000 119.3500  97.48000
## 224   224  4664.020      6.250000 120.1100  97.75000
## 225   225  4149.670      6.000000 120.8800  96.13000
## 226   226  4230.220      6.000000 122.0300  98.52000
## 227   227  4102.970      5.650000 122.4100  98.92000
## 228   228  4282.870      5.650000 123.1800  99.38000
## 229   229  4069.140      5.400000 124.3200  97.35000
## 230   230  4314.320      5.400000 125.4700  98.27000
## 231   231  4509.770      5.400000 126.2400  96.39000
## 232   232  4395.910      5.400000 126.2400  97.39000
## 233   233  3811.780      5.400000 125.4700  98.13000
## 234   234  2392.980      4.650000 124.7100  99.05000
## 235   235  1603.020      4.650000 125.8500  99.57000
## 236   236  2298.550      4.250000 126.2400  98.34000
## 237   237  2987.460      4.250000 127.0000  97.39000
## 238   238  3156.010      4.250000 128.5300  93.35000
## 239   239  3243.750      4.250000 129.3000  92.14000
## 240   240  3080.014      4.334102 130.2616  91.54226
## 241   241  3034.375      4.406620 130.9697  91.16057
## 242   242  3051.683      4.478941 131.4221  90.82893
## 243   243  3102.755      4.551333 131.9226  90.51423
## 244   244  3152.276      4.616707 132.0421  90.21824
## 245   245  3203.213      4.684645 132.1785  89.93399
## 246   246  3253.020      4.747952 132.2745  89.64473
## 247   247  3301.951      4.805900 132.2985  89.30638
## 248   248  3351.106      4.859537 132.3834  88.98787
## 249   249  3386.471      4.899344 132.6157  88.69173
#forecast cmort using mlp with forecasted xreg (don't need to forecast week.)
goldDF = data.frame(Date = ts(seq(1,239,1)),crude_oil = ts(gold$Crude_Oil), interest_rate = ts(gold$Interest_Rate), CPI = ts(gold$CPI),  USD_index = ts(gold$USD_Index))
fit.mlp = mlp(ts(gold$Gold_Price),reps = 20,comb = "mean",xreg = goldDF)
fit.mlp #
## MLP fit with 5 hidden nodes and 20 repetitions.
## Series modelled in differences: D1.
## Univariate lags: (1)
## 5 regressors included.
## - Regressor 1 lags: (1)
## - Regressor 2 lags: (1,4)
## - Regressor 3 lags: (3)
## - Regressor 4 lags: (1)
## - Regressor 5 lags: (1,3)
## Forecast combined using the mean operator.
## MSE: 172241.9491.
plot(fit.mlp)

fore.mlp = forecast(fit.mlp, h = 10, xreg = GDF_fore)
plot(fore.mlp)

#Plot
plot(seq(1,239,1), gold$Gold_Price, type = "l",xlim = c(0,250), ylim = c(0, 100000), ylab = "Gold Price", main = "10 Month Gold Price Forecast")
lines(seq(240,249,1), fore.mlp$mean, type = "l", col = "red")

fore.mlp
##     Point Forecast
## 240       55341.08
## 241       57510.26
## 242       59744.01
## 243       61894.69
## 244       64115.83
## 245       65927.09
## 246       67844.99
## 247       69826.77
## 248       71455.14
## 249       73212.25
#roll.win.rmse.nn.wge(series=gold$Gold_Price, horizon = 10, fit_model=fit.mlp)
#roll.win.rmse.nn.wgehp(series=gold$Gold_Price, horizon=10, fit_model=fit.mlp, xreg_input = goldDF)

# fit = mlp(ts(series[i:(i+(trainingSize-1))]), model = fit_model)

# x.n <- dim(xreg)[2]
#xm.n <- length(model$xreg.minmax)

#if (x.n != xm.n){
#          stop("Previous model xreg specification and new xreg inputs do not match.")
#        }
#Ensemble CODE - SHORT TERM 

ensemble  = (preds$fcst$y1[,1] + fore.mlp$mean)/2

#Plot
plot(seq(1,239,1), gold$Gold_Price, type = "l",xlim = c(0,250), ylab = "Gold Price", main = "10 Month Gold Price Forecast", ylim = c(0, 80000))
lines(seq(240,249,1), ensemble, type = "l", col = "red")